#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const int Mod = 1e9 + 7;
struct in {
  int L, R;
  friend bool operator<(in w, in v) { return w.R < v.R; }
} s[maxn];
int dp[maxn], sum[maxn], r[maxn];
int main() {
  int N, M, ans = 0;
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) scanf("%d%d", &s[i].L, &s[i].R);
  sort(s + 1, s + M + 1);
  for (int i = 1; i <= M; i++) r[i] = s[i].R;
  dp[0] = 1;
  sum[0] = 1;
  for (int i = 1; i <= M; i++) {
    int j = i;
    while (j + 1 <= M && s[j + 1].R == s[i].R) j++;
    for (int k = i; k <= j; k++) {
      int pos = lower_bound(r, r + M + 1, s[k].L) - r;
      if (pos > 0)
        dp[k] = (sum[i - 1] - sum[pos - 1] + Mod) % Mod;
      else
        dp[k] = sum[i - 1];
      sum[k] = (sum[k - 1] + dp[k]) % Mod;
      if (s[k].R == N) (ans += dp[k]) %= Mod;
    }
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}
