#include <bits/stdc++.h>
int A[400000], p[400000], R[400000], C[400000] = {0}, N;
void add(int x, int d) {
  int i;
  for (i = x; i <= N; i += i & (-i)) C[i] = (C[i] + d) % 1000000007;
}
int sum(int x) {
  int i, ans = 0;
  for (i = x; i > 0; i -= i & (-i)) ans = (ans + C[i]) % 1000000007;
  return ans;
}
int cmp(const void *a, const void *b) {
  int c, d;
  c = *(int *)a;
  d = *(int *)b;
  if (A[c] < A[d]) return -1;
  if (A[c] > A[d]) return 1;
  if (c < d) return -1;
  if (c > d) return 1;
  return 0;
}
int main() {
  int n, m, i, j, t, d, ans = 0;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    j = i << 1;
    scanf("%d%d", &A[j], &A[j + 1]);
    p[j] = j;
    p[j + 1] = j + 1;
  }
  t = m * 2;
  A[t] = n;
  p[t] = t;
  qsort(p, t + 1, sizeof(int), cmp);
  for (i = 0, j = 0; i <= t; i++) {
    if (i == 0 || A[p[i]] > A[p[i - 1]])
      R[p[i]] = ++j;
    else
      R[p[i]] = R[p[i - 1]];
  }
  N = j;
  if (A[p[0]] == 0) {
    add(1, 1);
    for (i = 0; i < t; i++) {
      if (p[i] % 2 == 1) {
        d = sum(R[p[i]] - 1) - sum(R[p[i] - 1] - 1);
        if (d < 0) d += 1000000007;
        add(R[p[i]], d);
      }
    }
    ans = sum(R[p[t]]) - sum(R[p[t]] - 1);
    if (ans < 0) ans += 1000000007;
  }
  printf("%d\n", ans);
  return 0;
}
