#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long INF = 10000000000;
int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<long long> area(2 * k, -1);
  long long cnt = 0, l, r;
  for (long long i = 0; i < k; i++) {
    cin >> l >> r;
    area[cnt] = l;
    area[cnt + 1] = r;
    cnt += 2;
  }
  map<long long, long long> count;
  area.erase(unique(area.begin(), area.end()), area.end());
  cnt = area.size();
  count[1] = 1;
  for (long long i = 1; i < n + 1 + 1; i++) {
    for (long long j = 0; j < cnt; j++) {
      count[i + area[j]] = (count[i + area[j]] + count[i]) % MOD2;
    }
  }
  cout << count[n] % MOD2 << endl;
}
