#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  vector<pair<int, int>> V(K);
  vector<long long> DP(400005);
  DP[0] = 1;
  for (int X = 0; X < K; X++) {
    int A, B;
    scanf("%d%d", &A, &B);
    V[X] = make_pair(A, B);
  }
  for (int X = 0; X < N - 1; X++) {
    if (DP[X] == 0) break;
    for (int Y = 0; Y < K; Y++) {
      int A, B;
      tie(A, B) = V[Y];
      for (int Z = X + A; Z <= min(X + B, N); Z++) {
        DP[Z] += DP[X];
        if (DP[Z] >= 998244353) {
          DP[Z] %= 998244353;
        }
      }
    }
  }
  cout << DP[N - 1] << endl;
}
