#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int n, k;
int s[20];
long long dp[200001];
long long ans = 0;
int main() {
  cin >> n >> k;
  for (int i = 0; i < (int)(k); i++) {
    int l, r;
    cin >> l >> r;
    s[2 * i] = l;
    s[2 * i + 1] = r;
  }
  for (int i = 0; i < (int)(n); i++) {
    dp[i] = 0;
  }
  dp[1] = 1;
  for (int p = 0; p < (int)(n); p++) {
    for (int i = 0; i < (int)(k); i++) {
      for (int j = s[2 * i]; j <= s[2 * i + 1]; j++) {
        if (i + 1 + j <= n) {
          dp[i + 1 + j] += dp[i + 1];
          dp[i + 1 + j] %= 998244353;
        }
      }
    }
  }
  cout << dp[n] % 998244353 << "\n";
  return 0;
}
