#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int num = 0;
  char c = getchar();
  if (c == '-') return -read();
  while (c >= '0' && c <= '9') {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num;
}
inline long long READ() {
  long long num = 0;
  char c = getchar();
  if (c == '-') return -READ();
  while (c >= '0' && c <= '9') {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num;
}
set<int> nums;
map<int, int> dy;
int cntdy;
int f[100007], t[100007];
int n, m;
vector<int> minf[200007];
int dp[200007], dpqzh[200007];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", f + i, t + i);
    nums.insert(f[i]);
    nums.insert(t[i]);
  }
  for (__typeof(nums.begin()) it = nums.begin(); it != nums.end(); it++)
    dy[*it] = cntdy++;
  if (!dy.count(0) || !dy.count(n)) return printf("0"), 0;
  n = dy[n];
  for (int i = 0; i < m; i++) {
    f[i] = dy[f[i]];
    t[i] = dy[t[i]];
    minf[t[i]].push_back(f[i]);
  }
  dp[0] = 1;
  dpqzh[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < ((int)(minf[i]).size()); j++)
      dp[i] = (dp[i] +
               (dpqzh[i - 1] - (minf[i][j] == 0 ? 0 : dpqzh[minf[i][j] - 1]) +
                1000000007) %
                   1000000007) %
              1000000007;
    dpqzh[i] = (dpqzh[i - 1] + dp[i]) % 1000000007;
  }
  return printf("%d\n", dp[n]), 0;
}
