#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll N, K, count1 = 0;
stack<ll> rote;
vector<ll> T;
void ST(ll sum) {
  if (sum == N) {
    count1++;
    return;
  }
  if (sum > N) return;
  for (ll i = 0; i < T.size(); i++) {
    ST(sum + T[i]);
  }
  return;
}
int main() {
  cin >> N >> K;
  set<ll> tile;
  for (ll i = 0; i < K; i++) {
    ll s1, s2;
    cin >> s1 >> s2;
    for (ll j = s1; j <= s2; j++) tile.insert(j);
  }
  for (ll i : tile) T.push_back(i);
  ST(1);
  cout << count1 << endl;
}
