#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long n, k;
vector<long long> vec;
long long dp[200009];
long long finds(long long in) {
  if (in > n) return 0;
  if (in == n) return 1;
  if (dp[in] != -1) return dp[in];
  long long ans = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (in + vec[i] > n) break;
    ans += finds(in + vec[i]);
    ans %= mod;
  }
  return dp[in] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  {
    memset(dp, -1, sizeof dp);
    long long a, b, c, d, i, j, k, l, m, sum = 0, temp = 0, f = 0, cnt = 0;
    cin >> n >> k;
    for (i = 0; i < k; i++) {
      cin >> a >> b;
      if (a == b)
        vec.push_back(a);
      else {
        for (j = a; j <= b; j++) vec.push_back(j);
      }
    }
    sort(vec.begin(), vec.end());
    cout << finds(1) << "\n";
  }
}
