#include <bits/stdc++.h>
using namespace std;
long long dp[200009], C[200009];
int n, m, sa, S, T, cnt;
struct SEC {
  int l, r;
} a[200009];
struct TA {
  int a, rk, i;
} ta[200009];
int read();
bool cmp(TA x, TA y) { return x.a < y.a; }
bool cmp2(SEC x, SEC y) { return x.r < y.r; }
void add(int x, long long va) {
  for (int i = x; i <= cnt; i += -i & i) (C[i] += va) %= 1000000007;
}
long long ask(int x, long long ret = 0) {
  if (x <= 0) return 0;
  for (int i = x; i; i -= -i & i) (ret += C[i]) %= 1000000007;
  return ret;
}
int main() {
  n = read() + 1, m = read();
  for (int i = 1; i <= m; ++i) {
    a[i].l = read() + 1, a[i].r = read() + 1;
    ta[++sa] = (TA){a[i].l, 2, i};
    ta[++sa] = (TA){a[i].r, 3, i};
  }
  ta[++sa] = (TA){1, 1, 0};
  ta[++sa] = (TA){n, n, 0};
  sort(ta + 1, ta + 1 + sa, cmp);
  ta[0].a = -1;
  for (int i = 1; i <= sa; ++i)
    if (ta[i].rk == 1)
      S = (cnt += ta[i].a != ta[i - 1].a);
    else if (ta[i].rk == n)
      T = (cnt += ta[i].a != ta[i - 1].a);
    else if (ta[i].rk == 2)
      a[ta[i].i].l = (cnt += ta[i].a != ta[i - 1].a);
    else
      a[ta[i].i].r = (cnt += ta[i].a != ta[i - 1].a);
  sort(a + 1, a + 1 + m, cmp2);
  dp[S] = 1;
  add(S, 1);
  for (int i = 1; i <= m; ++i) {
    int l = a[i].l, r = a[i].r;
    long long now = (ask(r - 1) - ask(l - 1) + 1000000007) % 1000000007;
    (dp[r] += now) %= 1000000007;
    add(r, now);
  }
  printf("%lld\n", dp[T]);
  return 0;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') f = (c == '-') ? -1 : f, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
