#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
map<int, int> dp, sum;
map<int, vector<int>> buses;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int f, t;
    cin >> f >> t;
    buses[f];
    buses[t];
    buses[t + 1].push_back(f + 1);
  }
  sum[1] = dp[1] = 1;
  int last = 1;
  for (auto bus : buses) {
    if (bus.first <= 1) continue;
    for (int p : bus.second) {
      dp[bus.first] =
          ((dp[bus.first] + sum[bus.first - 1] - sum[p - 1]) % MOD + MOD) % MOD;
    }
    sum[bus.first] = last = (last + dp[bus.first]) % MOD;
  }
  cout << dp[n + 1];
}
