#include <bits/stdc++.h>
using namespace std;
int Idou_W(int Kyori, vector<int> &Hohaba) {
  if (Kyori == 0) {
    return 1;
  }
  if (Kyori > 0 && Kyori < Hohaba.at(0)) {
    return 0;
  }
  int t = 0;
  for (int d : Hohaba) {
    int s = Idou_W(d, Hohaba) * Idou_W(Kyori - d, Hohaba);
    t += s;
  }
  return t;
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int>> Kukan(K, vector<int>(2));
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> Kukan.at(i).at(j);
    }
  }
  vector<int> Hohaba = {Kukan.at(0).at(0)};
  for (int i = 0; i < K; i++) {
    for (int j = Kukan.at(i).at(0); j <= Kukan.at(i).at(1); j++) {
      if (j > Kukan.at(0).at(0)) {
        Hohaba.push_back(j);
      }
    }
  }
  cout << Idou_W(N - 1, Hohaba) << endl;
}
