#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 100, M = 15, MOD = 998244353;
long long l[M];
long long r[M];
long long ans = 0;
long long mem[N];
bool flag[N];
long long n, m;
long long dfs(long long x) {
  if (x == n) {
    return 1;
  }
  if (flag[x]) return mem[x];
  long long ans = 0;
  for (long long i = 1; i <= m; i++)
    for (long long j = l[i]; j <= r[i]; j++) {
      if (x + j <= n) {
        ans = (ans + dfs(x + j)) % MOD;
      }
    }
  flag[x] = true;
  mem[x] = ans;
  return ans;
}
signed main() {
  memset(mem, 0, sizeof(mem));
  memset(flag, 0, sizeof(flag));
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) cin >> l[i] >> r[i];
  long long ans = dfs(1);
  cout << ans << endl;
}
