#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> LR(N + 1, false);
  set<int> base;
  for (int i = 0; i < K; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      base.insert(j);
    }
  }
  vector<vector<int> > sets(N + 1);
  sets[1] = vector<int>(N + 1, 0);
  sets[1][1] = 1;
  long long count = 0;
  for (int i = 2; i <= N; i++) {
    sets[i] = vector<int>(N + 1, 0);
    for (int j = 1; j <= N; j++) {
      if (sets[i - 1][j] == 0) continue;
      for (auto itr = base.begin(); itr != base.end(); itr++) {
        int num = *itr;
        if (j + num == N) count += sets[i - 1][j];
        if (j + num < N) sets[i][j + num] += sets[i - 1][j];
        count = count % 998244353;
      }
    }
    count = count % 998244353;
  }
  cout << count << endl;
  return 0;
}
