#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, pair<long long, long long>>> b;
long long aa[1000000];
int main() {
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    long long u, v;
    cin >> u >> v;
    b.push_back(make_pair(u, make_pair(1, i)));
    b.push_back(make_pair(v, make_pair(2, i)));
  }
  b.push_back(make_pair(0, make_pair(2, m)));
  sort(b.begin(), b.end());
  if (b[2 * m].first != n) {
    cout << 0;
    return 0;
  }
  long long cur = 2 * m;
  long long q = 0;
  long long ct = 0;
  while (b[cur].first == n) {
    ++q;
    aa[b[cur].second.second] = 1;
    --cur;
    ++ct;
  }
  while (ct != 0 && cur >= 0) {
    if (b[cur].second.first == 2) {
      int cur1 = cur;
      while (b[cur1].first == b[cur].first && b[cur1].second.first == 2) {
        aa[b[cur1].second.second] = q;
        --cur1;
        ct++;
      }
      q = q * (cur - cur1 + 1);
      q %= 1000000007;
      cur = cur1 + 1;
    } else {
      q -= aa[b[cur].second.second];
      if (q < 0) q += 1000000007;
      --ct;
    }
    --cur;
  }
  cout << aa[m] << endl;
  return 0;
}
