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