#include <bits/stdc++.h>
double eps = 1e-9;
using namespace std;
long long mod = 1000000007;
vector<pair<int, int> > v;
int n, m;
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second < b.second) {
    return true;
  }
  return false;
}
vector<pair<long long, long long> > vb;
vector<long long> par;
long long getsum(int a, int b) {
  int ind1, ind2;
  int low = 0, high = m + 1;
  while (low != high) {
    int mid = (low + high) / 2;
    if (vb[mid].first >= a) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  ind1 = low;
  low = 0;
  high = m + 1;
  while (low != high) {
    int mid = (low + high) / 2;
    if (vb[mid].first > b) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  low--;
  ind2 = low;
  if (ind1 <= ind2) {
    long long k = par[ind2] - (ind1 > 0 ? par[ind1 - 1] : 0);
    k %= mod;
    if (k < 0) {
      k += mod;
    }
    return k;
  } else {
    return 0;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end(), comp);
  vb.push_back(make_pair(0, 1));
  par.push_back(1);
  for (int i = 0; i < m; i++) {
    vb.push_back(make_pair(v[i].second, 0));
    par.push_back(1);
  }
  par.push_back(0);
  par.push_back(0);
  vb.push_back(make_pair(0x7fffffff, 0));
  vb.push_back(make_pair(0x7fffffff, 0));
  for (int i = 1; i <= m; i++) {
    vb[i].second = getsum(v[i - 1].first, v[i - 1].second - 1);
    par[i] = par[i - 1] + vb[i].second;
    par[i] %= mod;
  }
  long long sum = 0;
  for (int i = 1; i <= m; i++) {
    if (vb[i].first == n) {
      sum += vb[i].second;
      sum %= mod;
    }
  }
  cout << sum;
  return 0;
}
