#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int MAXN = 3e5 + 5;
const int MAXM = 1e7;
const int N = 1e6 + 10;
const double EPS = 1e-7;
long long i, j, k;
long long n, m, t;
pair<long long, long long> station[MAXN];
long long endStation[MAXN];
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second) return a.second < b.second;
  return a.first < b.first;
}
long long dp[MAXN], amount[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> station[i].first >> station[i].second;
    endStation[i] = station[i].second;
  }
  sort(endStation + 1, endStation + m + 1);
  sort(station + 1, station + m + 1, cmp);
  for (i = 1; i <= m; i++) {
    if (station[i].first == 0) dp[i] = 1;
    long long a =
        lower_bound(endStation + 1, endStation + m + 1, station[i].first) -
        endStation;
    long long b =
        lower_bound(endStation + 1, endStation + m + 1, station[i].second) -
        endStation;
    dp[i] = (dp[i] + amount[b] - amount[a] + MOD) % MOD;
    amount[i + 1] = (dp[i] + amount[i]) % MOD;
  }
  long long ans = 0;
  for (i = 1; i <= m; i++) {
    if (station[i].second == n) ans = (ans + dp[i]) % MOD;
  }
  cout << ans << endl;
  return 0;
}
