#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  long long N, K;
  cin >> N >> K;
  long long L, R;
  vector<long long> vec;
  for (long long i = 0; i < K; i++) {
    cin >> L >> R;
    for (long long j = L; j <= R; j++) {
      vec.push_back(j);
    }
  }
  sort(vec.begin(), vec.end());
  long long last = N / vec[0] + 1;
  vector<vector<long long> > dp(last + 1, vector<long long>(N + 1, 0));
  dp[0][1] = 1;
  for (long long i = 1; i <= last; i++) {
    for (long long j = 1; j <= N; j++) {
      for (long long k = 0; k < (long long)vec.size(); k++) {
        if (j + vec[k] <= N) {
          dp[i][j + vec[k]] = (dp[i][j + vec[k]] + dp[i - 1][j]) % mod;
        } else {
          break;
        }
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i <= last; i++) {
    ans = (ans + dp[i][N]) % mod;
  }
  cout << ans << endl;
}
