#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long n, m;
map<long long, long long> mp;
map<long long, long long> done;
long long bs[200009];
pair<long long, long long> e[200009];
vector<long long> v[200009];
vector<long long> vv;
void edit() {
  sort(vv.begin(), vv.end());
  if (vv.size() <= 1) cout << 0 << endl, exit(0);
  if (vv[0] != 0 || vv[vv.size() - 1] != n)
    cout << 0 << endl, exit(0);
  else
    bs[0] = 1;
  for (int i = 0; i < vv.size(); i++) {
    mp[vv[i]] = i;
    vv[i] = i;
  }
  for (int i = 0; i < m; i++) {
    e[i].first = mp[e[i].first];
    e[i].second = mp[e[i].second];
    long long a = e[i].first, b = e[i].second;
    v[b].push_back(a);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    e[i] = {a, b};
    if (!mp[a]) vv.push_back(a), mp[a] = 1;
    if (!mp[b]) vv.push_back(b), mp[b] = 1;
  }
  edit();
  long long ans = 0;
  for (int i = 1; i < vv.size(); i++) {
    for (int j = 0; j < v[vv[i]].size(); j++) {
      int u = v[vv[i]][j];
      long long xxx = bs[i - 1] % mod;
      if (u) xxx = (xxx - bs[u - 1] + mod) % mod;
      bs[i] = (bs[i] % mod + xxx % mod) % mod;
    }
    if (i == vv.size() - 1) {
      cout << bs[i] % mod << endl;
      exit(0);
    }
    bs[i] = (bs[i] % mod + bs[i - 1] % mod) % mod;
  }
  cout << 0 << endl;
}
