#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 998244353;

template<const long long MOD>
class Modint{
    public:
        Modint() : x(0) {

        }

        Modint(long long y) : x((y % MOD + MOD) % MOD) {

        }

        Modint& operator+=(const Modint& p){
            if((x += p.x) >= MOD) x -= MOD;
            return *this;
        }

        Modint& operator-=(const Modint& p){
            if((x += MOD - p.x) >= MOD) x -= MOD;
            return *this;
        }

        Modint& operator*=(const Modint& p){
            x = x * p.x % MOD;
            return *this;
        }

        Modint& operator/=(const Modint& p){
            *this *= p.inverse();
            return *this;
        }

        Modint operator-() const {
            return Modint(-x);
        }

        Modint operator+(const Modint& p) const {
            return Modint(*this) += p;
        }

        Modint operator-(const Modint& p) const {
            return Modint(*this) -= p;
        }

        Modint operator*(const Modint& p) const {
            return Modint(*this) *= p;
        }

        Modint operator/(const Modint& p) const {
            return Modint(*this) /= p;
        }

        bool operator==(const Modint& p) const {
            return x == p.x;
        }

        bool operator!=(const Modint& p) const {
            return !(*this == p);
        }

        bool operator<(const Modint& p) const {
            return x < p.x;
        }

        bool operator>(const Modint& p) const {
            return x > p.x;
        }

        bool operator<=(const Modint& p) const {
            return !(*this > p);
        }

        bool operator>=(const Modint& p) const {
            return !(*this < p);
        }

        Modint inverse() const {
            long long a = x, b = MOD, u = 1, v = 0;
            while(b > 0){
                long long t = a / b;
                a -= t * b;
                swap(a, b);
                u -= t * v;
                swap(u, v);
            }
            return Modint(u);
        }

        Modint pow(long long n) const {
            Modint ret(1), mul(x);
            while(n > 0){
                if(n & 1) ret *= mul;
                mul *= mul;
                n >>= 1;
            }
            return ret;
        }

        friend ostream &operator<<(ostream& os, const Modint& p){
            return os << p.x;
        }

        friend istream &operator>>(istream& is, Modint& a){
            long long t;
            cin >> t;
            a = Modint<MOD>(t);
            return is;
        }

        explicit operator long long() const {
            return x;
        }

        static long long get_mod(){
            return MOD;
        }

    private:
        long long x;
};

ll N, K;
vector<pll> S;
ll dp[200010];
using mint = Modint<MOD>;

struct FenwickTree {
  vector<mint> v;
  int n;
  FenwickTree(int n) : n(n), v(n) {}
  void add(int i, mint x) {
    i++;
    while (i <= n) {
      v[i - 1] += x;
      i += i & -i;
    }
  }
  mint get(int i) {
    mint r = 0;
    while (i >= 1) {
      r += v[i - 1];
      i -= i & -i;
    }
    return r;
  }
};
 
struct ExFenwickTree {
  FenwickTree p, q;
  ExFenwickTree(int n) : p(n + 1), q(n + 1) {}
  void add(int l, int r, mint w) {
    p.add(l, -w * l);
    p.add(r, w * r);
    q.add(l, w);
    q.add(r, -w);
  }
  mint get(int r) {
    return p.get(r) + q.get(r) * r;
  }
};

signed main(){
    cin >> N >> K;
    ll l, r;
    REP(i, K){
        cin >> l >> r;
        S.push_back({l, r});
    }
    ExFenwickTree bit(2 * N);
    bit.add(1, 2, mint(1));
    FOR(i, 1, N + 1){
        for(auto p : S){
            bit.add(i + p.first, i + p.second + 1, bit.get(i + 1) - bit.get(i));
        }
    }
    PRINT(bit.get(N + 1) - bit.get(N));
    return 0;
}

Measured memory_bytes: 9596