#include <bits/stdc++.h>
using namespace std;
int n, k;
const int mod = 998244353;
int totalNoJumps(int currentIndex, vector<pair<int, int>>& possible,
                 vector<int>& dp) {
  if (currentIndex == n) {
    return 1;
  }
  int cnt = 0;
  if (dp[currentIndex] != -1) {
    return dp[currentIndex];
  } else {
    for (int i = 0; i < k; i++) {
      for (int j = possible[i].first; j <= possible[i].second; j++) {
        if (currentIndex + j <= n) {
          cnt =
              (cnt % mod + totalNoJumps(currentIndex + j, possible, dp) % mod) %
              mod;
        }
      }
    }
    dp[currentIndex] = cnt;
  }
  return dp[currentIndex];
}
void solve() {
  cin >> n >> k;
  int i, a, b;
  vector<pair<int, int>> possible;
  vector<int> dp(n + 5, -1);
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    possible.push_back(make_pair(a, b));
  }
  cout << totalNoJumps(1, possible, dp) << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
