#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll mod = 998244353;
int main() {
  ll ans = 0;
  int N, K;
  cin >> N >> K;
  vector<int> S;
  for (int i = 0; i < (K); ++i) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      S.push_back(i);
    }
  }
  ll l = S.size();
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int now = q.front();
    for (int i = 0; i < (l); ++i) {
      now += S[i];
      if (now == N) {
        ans++;
        break;
      }
      if (now > N) {
        break;
      } else {
        q.push(now);
        i = 0;
      }
    }
    q.pop();
  }
  cout << ans << endl;
}
