#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int lowbit(int x) { return x & (-x); }
int n, m;
vector<pair<int, int> > bus;
int a[200010];
map<int, int> mp;
int f[200010];
int sum[200010];
bool com(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
int main() {
  scanf("%d%d", &n, &m);
  bool ok1 = false, ok2 = false;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    bus.push_back(make_pair(x, y));
    mp[x], mp[y];
    if (y == n) ok1 = true;
    if (x == 0) ok2 = true;
  }
  if (!ok1 || !ok2) {
    cout << 0;
    return 0;
  }
  int cur = 0;
  for (map<int, int>::iterator i = mp.begin(); i != mp.end(); i++) {
    i->second = cur++;
  }
  for (int i = 0; i < m; i++) {
    bus[i].first = mp[bus[i].first];
    bus[i].second = mp[bus[i].second];
  }
  sort(bus.begin(), bus.end(), com);
  f[0] = 1, sum[1] = 1;
  for (int i = 1; i < cur; i++) {
    f[i] = 0;
    while (!bus.empty() && bus.back().second == i) {
      f[i] += sum[i] - sum[bus.back().first];
      if (f[i] < 0) f[i] += mod;
      f[i] %= mod;
      bus.pop_back();
    }
    sum[i + 1] = (sum[i] + f[i]) % mod;
  }
  cout << f[cur - 1] << endl;
  return 0;
}
