#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, unsigned long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x;
    }
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long int powermod(long long int x, unsigned long long int y,
                       long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const long long int mod = 998244353;
const long long int inf = 1e18;
long long int n, k;
vector<long long int> v;
long long int dp[200005];
long long int f(long long int i) {
  if (i > n) {
    return 0;
  }
  if (i == n) {
    return 1;
  }
  if (dp[i] != -1) {
    return dp[i];
  }
  long long int ans = 0;
  for (auto &val : v) {
    ans += (f(i + val));
    ans %= mod;
  }
  dp[i] = ans;
  return ans;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  long long int l, r;
  cin >> n >> k;
  for (long long int i = (long long int)(0); i < (long long int)(k); i++) {
    cin >> l >> r;
    for (long long int j = (long long int)(l); j < (long long int)(r + 1);
         j++) {
      v.push_back(j);
    }
  }
  sort((v).begin(), (v).end());
  cout << f(1) << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
