#include <bits/stdc++.h>
using namespace std;
long long sum[1000010] = {0};
long long p = 1e9 + 7;
long long sett[1000010] = {0};
long long k = 1;
long long ans(long long i) {
  long long s = 0;
  while (i != 0) {
    s = (s + sum[i]) % p;
    i -= i & -i;
  }
  return s;
}
void add(long long i, long long ans) {
  while (i <= k) {
    sum[i] = (sum[i] + ans) % p;
    i += i & -i;
  }
}
int main() {
  long long n, m, i, j, s = 0, c = 0;
  cin >> n >> m;
  vector<pair<long long, long long> > a(m);
  for (i = 0; i < m; i++) {
    cin >> a[i].second >> a[i].first;
    sett[k++] = a[i].second;
    sett[k++] = a[i].first;
  }
  sort(sett + 1, sett + k + 1);
  sort(a.begin(), a.end());
  for (i = 0; i < m; i++) {
    long long ss = lower_bound(sett + 1, sett + k + 1, a[i].second) - sett;
    long long tt = lower_bound(sett + 1, sett + k + 1, a[i].first) - sett;
    if (a[i].second == 0) c += 1;
    c += ans(tt - 1) - ans(ss - 1);
    c = (c + p) % p;
    add(tt, c);
    if (a[i].first == n) s = ans(tt) - ans(tt - 1);
    c = 0;
  }
  cout << (s + p) % p;
  return 0;
}
