#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long MOD = 998244353;
long long n, k;
long long m;
vector<pair<long long, long long> > a;
class Fenwick {
 public:
  vector<long long> ft;
  void init(long long n) { ft.resize(n + 1); }
  long long g(long long x) { return x & (-x); }
  void get(long long& x, long long y) {
    x += y;
    x %= MOD;
  }
  long long sum(long long pos) {
    long long ans = 0;
    for (; pos; pos -= g(pos)) get(ans, ft[pos]);
    return ans;
  }
  long long sum(long long l, long long r) {
    return sum(r) - (l == 0 ? 0 : sum(l - 1));
  }
  void upd(long long pos, long long val) {
    for (; pos < ft.size(); pos += g(pos)) {
      get(ft[pos], val);
    }
  }
};
void solve() {
  cin >> n >> k;
  a.resize(k);
  for (long long i = 0; i < (k); i++) {
    long long x, y;
    cin >> a[i].first >> a[i].second;
  }
  Fenwick ft;
  ft.init(4 * N);
  ft.upd(1, 1);
  ft.upd(2, -1);
  for (long long i = 1; i < n; i++) {
    long long here = ft.sum(i);
    for (auto [x, y] : a) {
      ft.upd(i + x, here);
      ft.upd(i + y + 1, -here);
    }
  }
  cout << ft.sum(n) << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
