#include <bits/stdc++.h>
using namespace std;
long long N, M, cnt, l, r;
pair<long long, long long> B[300100];
vector<long long> A[300100];
set<long long> S;
map<long long, long long> V;
void add(long long &x, long long y) {
  x += (y % 1000000007);
  while (x < 0) x += 1000000007;
  while (x >= 1000000007) x -= 1000000007;
}
long long dp[300100], cdp[300100];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (long long I = 1; I <= M; I++) {
    cin >> B[I].first >> B[I].second;
    S.insert(B[I].first);
    S.insert(B[I].second);
  }
  S.insert(0);
  S.insert(N);
  for (typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
    V[*it] = ++cnt;
  N = V[N];
  for (long long I = 1; I <= M; I++) {
    assert(((V).find(B[I].first) != (V).end()));
    l = V[B[I].first];
    assert(((V).find(B[I].second) != (V).end()));
    r = V[B[I].second];
    A[r].push_back(l);
  }
  dp[1] = cdp[1] = 1;
  for (long long I = 2; I <= N; I++) {
    for (typeof((A[I]).begin()) it = (A[I]).begin(); it != (A[I]).end(); it++) {
      l = *it;
      add(dp[I], cdp[I - 1] - cdp[l - 1]);
    }
    add(cdp[I], cdp[I - 1] + dp[I]);
  }
  cout << dp[N] << endl;
}
