#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int n, k, x, y;
pair<int, int> arr[200005];
vector<int> dis;
int dp[200005];
int add(int x, int y) { return ((x % mod) + (y % mod)) % mod; }
int solve() {
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (int j = 0; j < dis.size(); j++) {
      if (i > dis[j]) {
        dp[i] = add(dp[i], dp[i - dis[j]]);
      }
    }
  }
  return dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    arr[i] = {x, y};
    for (int j = arr[i].first; j <= arr[i].second; j++) {
      dis.push_back(j);
    }
  }
  cout << solve() << "\n";
  return 0;
}
