#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
};
queue<node> LR;
queue<int> bfs;
vector<int> v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  int ans = 0;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    node temp;
    cin >> temp.l >> temp.r;
    LR.push(temp);
  }
  for (int i = 1; i <= K; i++) {
    for (int j = LR.front().l; j <= LR.front().r; j++) v.push_back(j);
    LR.pop();
  }
  bfs.push(1);
  do {
    int x = bfs.front();
    bfs.pop();
    for (int i = 0; i < v.size(); i++) {
      if (x + v[i] > N) break;
      if (x + v[i] == N) {
        ans++;
        break;
      }
      bfs.push(x + v[i]);
    }
  } while (!bfs.empty());
  cout << ans;
  return 0;
}
