#include <bits/stdc++.h>
using namespace std;
long long Set(long long N, long long pos) { return N = N | (1LL << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }
long long vis[200005], n, q;
vector<long long> v;
long long dp[200005];
long long solve(long long x) {
  if (x == n) return 1;
  if (x > n) return 0;
  if (dp[x] != -1) return dp[x];
  long long ans = 0;
  for (long long i = 0; i < v.size(); i++) {
    ans = ans % 998244353 + solve(x + v[i]);
  }
  return dp[x] = ans % 998244353;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(dp, -1, sizeof dp);
  cin >> n >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    for (long long i = x; i <= y; i++) {
      if (vis[i] == 0) {
        v.push_back(i);
        vis[i] = 1;
      }
    }
  }
  sort(v.begin(), v.end());
  cout << solve(1);
}
