#include <bits/stdc++.h>
using namespace std;
struct node {
  int sar, tah, Index;
  bool type;
  node(int st, int en, int Indx, bool t) {
    sar = st;
    tah = en;
    Index = Indx;
    type = t;
  }
};
const long long MOD = (1000 * 1000 * 1000 + 7);
vector<node> Stations;
long long dp[1000000], Ans, Now, now = 1;
map<long long, long long> LastValue, Value;
bool kch(node l, node r) {
  int L, R;
  if (l.type)
    L = l.tah;
  else
    L = l.sar;
  if (r.type)
    R = r.tah;
  else
    R = r.sar;
  if (L == R) return l.type < r.type;
  return L < R;
}
int main() {
  int n, m, f = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    node st(a, b, i, 0), en(a, b, i, 1);
    Stations.push_back(st);
    Stations.push_back(en);
  }
  if (!m) {
    cout << 0 << endl;
    return 0;
  }
  sort(Stations.begin(), Stations.end(), kch);
  if (Stations[0].sar) now = 0;
  for (int i = 0; i < Stations.size(); i++) {
    if (i) now = 0;
    if (!Stations[i].type) {
      LastValue[Stations[i++].Index] = Now;
      while (i < Stations.size() && Stations[i].sar == Stations[i - 1].sar &&
             !Stations[i].type && !Stations[i - 1].type)
        LastValue[Stations[i++].Index] = Now;
      i--;
    } else {
      Value[Stations[i].Index] = MOD + Now - LastValue[Stations[i].Index];
      now += Value[Stations[i++].Index];
      while (i < Stations.size() && Stations[i].tah == Stations[i - 1].tah &&
             Stations[i].type && Stations[i - 1].type) {
        Value[Stations[i].Index] = MOD + Now - LastValue[Stations[i].Index];
        now += Value[Stations[i].Index];
        now %= MOD;
        i++;
      }
      i--;
    }
    Now += now;
    Now %= MOD;
  }
  for (int i = 0; i < Stations.size(); i++)
    if (Stations[i].tah == n && Stations[i].type)
      Ans = (Ans + Value[Stations[i].Index]) % MOD;
  cout << Ans << endl;
}
