#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main(int argc, char* argv[]) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  vector<int> e(m);
  for (int i = 0; i < m; ++i) {
    int s, t;
    cin >> s >> t;
    v[i] = make_pair(t, s);
    e[i] = t;
  }
  sort(v.begin(), v.end());
  sort(e.begin(), e.end());
  vector<int> s(m + 1), a(m);
  s[0] = 0;
  for (int i = 0; i < m; ++i) {
    int f = lower_bound(e.begin(), e.end(), v[i].second) - e.begin();
    int t = lower_bound(e.begin(), e.end(), v[i].first) - e.begin();
    s[i + 1] = s[i];
    a[i] = 0;
    if (f < t) a[i] += s[t] - s[f];
    if (v[i].second == 0) a[i]++;
    a[i] += mod;
    a[i] %= mod;
    s[i + 1] += a[i];
    s[i + 1] %= mod;
  }
  int r = 0, i = m - 1;
  while ((i >= 0) && (v[i].first == n)) {
    r = (r + a[i]) % mod;
    i--;
  }
  cout << r << endl;
  return 0;
}
