#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
pair<int, int> s[100001];
long long dp[100001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &s[i].first, &s[i].second);
  }
  sort(s + 1, s + m + 1, [](pair<int, int> a, pair<int, int> b) {
    return a.second < b.second || a.second == b.second && a.first < b.first;
  });
  for (int i = 1; i <= m; ++i) {
    int low1 = 1;
    int high1 = i - 1;
    while (low1 < high1) {
      int mid = (low1 + high1) / 2;
      if (s[mid].second < s[i].first) {
        low1 = mid + 1;
      } else {
        high1 = mid;
      }
    }
    int low2 = 1;
    int high2 = i;
    while (low2 < high2) {
      int mid = (low2 + high2) / 2;
      if (s[mid].second < s[i].second) {
        low2 = mid + 1;
      } else {
        high2 = mid;
      }
    }
    if (s[low1].second < s[i].first) {
      low1 = -1;
    }
    if (low2 == 1) {
      low2 = -1;
    }
    long long d = 0;
    if (low1 < low2 && low1 != -1 && low2 != -1) {
      d += (dp[low2 - 1] - dp[low1 - 1]) + MOD;
    }
    d += (s[i].first == 0);
    dp[i] = (dp[i - 1] + d) % MOD;
  }
  int ans = 0;
  int i = m + 1;
  while (i >= 1 && s[i - 1].second == n) {
    --i;
  }
  cout << (i == m + 1 ? 0 : (dp[m] - dp[i - 1] + MOD) % MOD) << endl;
  return 0;
}
