#include <bits/stdc++.h>
using namespace std;
template <typename first>
inline first abs(const first& a) {
  return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
  return a * a;
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;
const int N = 200 * 1000 + 13;
int n, m, x;
int lf[N], rg[N];
vector<pair<int, int> > v;
int t[4 * N];
const int mod = 1000 * 1000 * 1000 + 7;
int sum(int idx, int lf, int rg, int l, int r) {
  if (lf == l && rg == r) return t[idx];
  int res = 0;
  int mid = (lf + rg) >> 1;
  if (l <= mid) res += sum(2 * idx + 1, lf, mid, l, min(mid, r));
  if (r > mid) res += sum(2 * idx + 2, mid + 1, rg, max(l, mid + 1), r);
  if (res >= mod) res -= mod;
  return res;
}
void upd(int idx, int lf, int rg, int pos, int val) {
  if (lf == rg) {
    t[idx] += val;
    if (t[idx] >= mod) t[idx] -= mod;
    return;
  }
  int mid = (lf + rg) >> 1;
  if (pos <= mid)
    upd(2 * idx + 1, lf, mid, pos, val);
  else
    upd(2 * idx + 2, mid + 1, rg, pos, val);
  t[idx] = t[2 * idx + 1] + t[2 * idx + 2];
  if (t[idx] >= mod) t[idx] -= mod;
}
int main() {
  cin >> x >> m;
  for (int i = 0; i < int(m); i++) {
    scanf("%d%d", &lf[i], &rg[i]);
    v.push_back(make_pair((rg[i]), (i)));
  }
  v.push_back(make_pair((0), (-1)));
  sort((v).begin(), (v).end());
  n = int((v).size());
  upd(0, 0, n - 1, 0, 1);
  int ans = 0;
  for (int i = 1; i <= int(n - 1); i++) {
    int curlf = lf[v[i].second];
    int idxlf =
        int(lower_bound((v).begin(), (v).end(), make_pair((curlf), (-1))) -
            v.begin());
    int idxrg =
        int(lower_bound((v).begin(), (v).end(), make_pair((v[i].first), (-1))) -
            v.begin()) -
        1;
    if (idxlf > idxrg) continue;
    int curv = sum(0, 0, n - 1, idxlf, idxrg);
    upd(0, 0, n - 1, i, curv);
    if (curlf <= x && x <= v[i].first) ans = (ans + curv) % mod;
  }
  cout << ans << endl;
  return 0;
}
