#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  bool ret = (a < b);
  if (ret) {
    a = b;
  }
  return ret;
}
template <class T>
inline bool chmin(T& a, T b) {
  bool ret = (b < a);
  if (ret) {
    a = b;
  }
  return ret;
}
const int INF = 1000000000;
const int MOD = 998244353;
const int DEFAULT_MOD = 0;
const int DEFAULT_SIZE = 0;
struct BIT {
  int n;
  int mod;
  std::vector<int> d;
  BIT(int n = DEFAULT_SIZE, int mod = DEFAULT_MOD) : n(n), mod(mod), d(n + 1) {}
  void add(int i, int x = 1) {
    for (i++; i <= n; i += i & -i) {
      d[i] += x;
      if (mod) {
        d[i] %= mod;
      }
    }
  }
  int sum(int i) {
    int x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
      if (mod) {
        x %= mod;
      }
    }
    return x;
  }
};
struct BIT2 {
  BIT2(int n = DEFAULT_SIZE, int mod = DEFAULT_MOD) : bit(n + 1, mod) {}
  void add(int l, int r, int x = 1) {
    bit.add(l, x);
    bit.add(r + 1, -x);
  }
  int val(int i) { return bit.sum(i); }

 private:
  BIT bit;
};
int n, k;
int dp[200001];
int solve(int x) {
  int ret = 0;
  if (1 < x) {
    ret = dp[x];
    if (ret < 0) {
      dp[x] = ret;
    }
  } else if (x == 1) {
    ret = 1;
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  int l[10];
  int r[10];
  for (int i = 0; i < int(k); ++i) cin >> l[i] >> r[i];
  BIT2 bit(410000, 998244353);
  bit.add(1, 1);
  for (int base = 1; base < n; ++base) {
    for (int i = 0; i < int(k); ++i) {
      int x = base + l[i];
      int y = base + r[i];
      if (x <= n) {
        bit.add(x, min(y, n), bit.val(base));
      }
    }
  }
  cout << bit.val(n) << endl;
  return 0;
}
