#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k2;
  cin >> n >> k2;
  int dp[n];
  for (int i = 0; i < n; i++) {
    dp[i] = 0;
  }
  dp[0] = 1;
  int l[k2], r[k2];
  for (int i = 0; i < k2; i++) {
    cin >> l[i] >> r[i];
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < k2; i++) {
      for (int j = l[i]; j <= r[i]; j++) {
        if (k + j >= n) break;
        if (dp[k] != 0) {
          dp[k + j] += dp[k];
          dp[k + j] %= 998244353;
        }
      }
    }
  }
  cout << dp[n - 1] << endl;
}
