#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int MOD = 998244353;
long long dp[200005];
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < (k); ++i) cin >> l[i] >> r[i];
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      for (int d = l[j]; d <= r[j]; d++) {
        if (i - d >= 0) {
          dp[i] += dp[i - d];
          dp[i] %= MOD;
        }
      }
    }
  }
  cout << dp[n - 1] << endl;
}
