#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)(1e9 + 7);
const int MAXN = 1e6 + 5;
pair<long long, long long> p[MAXN << 2];
long long dp[MAXN << 2];
vector<long long> a[MAXN << 2];
long long sum[MAXN << 2];
int main() {
  long long m, n, i, j, k;
  vector<long long> v;
  ios::sync_with_stdio(false);
  ;
  cin >> m >> n;
  map<long long, bool> mp;
  if (n == 0) {
    printf("%d\n", m == 0 ? 1 : 0);
    return 0;
  }
  for (i = 1; i <= n; i++) {
    cin >> p[i].first >> p[i].second;
    if (!mp[p[i].first]) v.push_back(p[i].first);
    mp[p[i].first] = 1;
    if (!mp[p[i].second]) v.push_back(p[i].second);
    mp[p[i].second] = 1;
  }
  sort((v).begin(), (v).end());
  if (v[v.size() - 1] != m || v[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 1; i <= n; i++) {
    p[i].first =
        lower_bound((v).begin(), (v).end(), p[i].first) - v.begin() + 1;
    p[i].second =
        lower_bound((v).begin(), (v).end(), p[i].second) - v.begin() + 1;
    a[p[i].second].push_back(p[i].first);
  }
  m = v.size();
  dp[1] = sum[1] = 1;
  for (i = 1; i <= m; i++) {
    for (j = 0; j < a[i].size(); j++) {
      long long l = a[i][j], r = i - 1;
      if (l > r)
        continue;
      else {
        dp[i] += (sum[r] - sum[l - 1] + mod) % mod;
        dp[i] %= mod;
      }
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << dp[m] << endl;
  return 0;
}
