#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int st[400000], lz[400000];
int query(int x, int n, int l, int r) {
  if (l == r)
    return lz[n];
  else {
    int m = (l + r) / 2;
    if (lz[n]) {
      lz[2 * n] = (lz[2 * n] + lz[n]) % MOD;
      lz[2 * n + 1] = (lz[2 * n + 1] + lz[n]) % MOD;
      lz[n] = 0;
    }
    if (x <= m)
      return query(x, 2 * n, l, m);
    else
      return query(x, 2 * n + 1, m + 1, r);
  }
}
void update(int x, int y, int v, int n, int l, int r) {
  if (x <= l && r <= y)
    lz[n] = (lz[n] + v) % MOD;
  else {
    int m = (l + r) / 2;
    if (lz[n]) {
      lz[2 * n] = (lz[2 * n] + lz[n]) % MOD;
      lz[2 * n + 1] = (lz[2 * n + 1] + lz[n]) % MOD;
      lz[n] = 0;
    }
    if (x <= m) update(x, y, v, 2 * n, l, m);
    if (y > m) update(x, y, v, 2 * n + 1, m + 1, r);
  }
}
struct sg {
  int s, e;
  bool operator<(const sg &p) const { return (e < p.e); }
};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<sg> sr(m);
  vector<int> e;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &sr[i].s, &sr[i].e);
    e.push_back(sr[i].e);
  }
  sort(sr.begin(), sr.end());
  sort(e.begin(), e.end());
  int anw = 0;
  for (int i = m - 1; i >= 0; i--) {
    int l = lower_bound(e.begin(), e.end(), sr[i].s) - e.begin();
    int u = lower_bound(e.begin(), e.end(), sr[i].e) - e.begin();
    u--;
    if (sr[i].e == n) update(i, i, 1, 1, 0, m - 1);
    int t = query(i, 1, 0, m - 1);
    if (!sr[i].s) anw = (anw + t) % MOD;
    if (l > u) continue;
    update(l, u, t, 1, 0, m - 1);
  }
  printf("%d\n", anw);
}
