#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops"
using namespace std;
void mahakal() {}
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
const long long maxN = 3e5 + 5;
long long n, k;
vector<long long> coin;
array<long long, 2> a[maxN];
long long solve(long long idx, long long n, long long sum,
                vector<vector<long long>>& dp) {
  if (idx >= n) {
    if (sum == 0)
      return 1;
    else
      return 0;
  }
  if (sum == 0) return 1;
  if (sum < 0) return 0;
  if (dp[idx][sum] != -1) return dp[idx][sum];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans = (ans + solve(i, n, sum - coin[i], dp) % 998244353) % 998244353;
  }
  return dp[idx][sum] = ans;
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    cin >> a[i][0] >> a[i][1];
  }
  for (long long i = 0; i < k; i++) {
    for (long long j = a[i][0]; j <= a[i][1]; j++) {
      coin.push_back(j);
    }
  }
  vector<vector<long long>> dp(coin.size(), vector<long long>(n + 1, -1));
  long long ans = solve(0, coin.size(), n - 1, dp);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) solve();
  return 0;
}
