#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MOD2 = 15000007;
const long long int MAX = 9187201950435737471;
const int N = 100005;
const long long int INF = 1e17;
const long double PI = acos(-1);
int n, k;
vector<int> v;
long long int dp[2 * N];
long long int f(int idx) {
  if (idx == n) {
    return 1;
  }
  long long int &ret = dp[idx];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i < v.size(); i++) {
    if (idx + v[i] <= n) {
      ret += f(idx + v[i]);
      ret %= 998244353;
    } else
      break;
  }
  return ret;
}
void solve(int T) {
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  cout << f(1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  for (int i = 1; i <= T; i++) {
    solve(i);
  }
  return 0;
}
