#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10;
int const M = 1e9 + 7;
vector<int> e[N];
vector<int> stop;
int s[N], t[N];
int f[N], _g[N], *g = _g + 1;
int id(int x) {
  return lower_bound(stop.begin(), stop.end(), x) - stop.begin();
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> t[i];
    stop.push_back(t[i]);
  }
  stop.push_back(0);
  sort(stop.begin(), stop.end());
  stop.erase(unique(stop.begin(), stop.end()), stop.end());
  if (stop.back() != n) return puts("0"), 0;
  for (int i = 0; i < m; ++i) e[id(t[i])].push_back(id(s[i]));
  int sz = (int)stop.size();
  f[0] = 1, g[0] = 1;
  for (int i = 1; i < sz; ++i) {
    for (auto j : e[i]) {
      f[i] = (f[i] + (g[i - 1] - g[j - 1]) % M) % M;
    }
    g[i] = (g[i - 1] + f[i]) % M;
  }
  if (f[sz - 1] < 0) f[sz - 1] += M;
  cout << f[sz - 1];
  return 0;
}
