#include <bits/stdc++.h>
using namespace std;
const int MX = 1234567;
int N, M;
int dp[MX];
int pref[MX];
map<int, int> h;
pair<int, int> p[MX];
int j;
vector<vector<int> > G(MX);
int md = 1e9 + 7;
int main() {
  scanf("%d%d", &N, &M);
  int mx = -1, mn = N + 1;
  for (int i = 0; i < M; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    mn = min(mn, l);
    mx = max(mx, r);
    ++h[l];
    ++h[r];
    p[i].first = l;
    p[i].second = r;
  }
  if (mn || mx != N || !M) {
    cout << 0 << "\n";
  } else {
    ++h[0];
    ++h[N];
    for (auto cur : h) h[cur.first] = j++;
    for (int i = 0; i < M; i++) G[h[p[i].second]].push_back(h[p[i].first]);
    dp[0] = pref[0] = 1;
    for (int i = 1; i < j; i++) {
      for (int k = 0; k < G[i].size(); k++) {
        int u = G[i][k];
        dp[i] += pref[i - 1] - pref[u - 1];
        while (dp[i] < 0) dp[i] += md;
        dp[i] %= md;
      }
      pref[i] = dp[i];
      pref[i] += pref[i - 1];
      pref[i] %= md;
    }
    cout << dp[j - 1];
  }
  return 0;
}
