#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long n, k;
int arr[10][2];
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 (long long i = 0; i < k; i++) {
    for (long long j = arr[i][0]; j <= arr[i][1]; j++) {
      ans += finds(in + j);
      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, l, m, sum = 0, temp = 0, f = 0, cnt = 0;
    cin >> n >> k;
    for (i = 0; i < k; i++) {
      cin >> arr[i][0] >> arr[i][1];
    }
    cout << finds(1) << "\n";
  }
}
