#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, a, b;
  scanf("%d%d", &N, &M);
  pair<int, int> v[M];
  int ed[M];
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &a, &b);
    v[i] = pair<int, int>(b, a);
    ed[i] = b;
  }
  sort(v, v + M);
  sort(ed, ed + M);
  int ans[M], sum[M];
  sum[0] = 0;
  sum[1] = ans[0] = (v[0].second == 0);
  for (int i = 1; i < M; i++) {
    int q = lower_bound(ed, ed + M, v[i].second) - ed;
    int r = lower_bound(ed, ed + M, v[i].first) - ed;
    int diff = (sum[r] - sum[q] + 1000000007) % 1000000007;
    ans[i] = diff + (v[i].second == 0);
    sum[i + 1] = (sum[i] + ans[i]) % 1000000007;
  }
  long long output = 0, i = M - 1;
  while (v[i].first == N) {
    output = (output + ans[i]) % 1000000007;
    i--;
  }
  cout << output << endl;
  return 0;
}
