#include <bits/stdc++.h>
using namespace std;

struct FastIO {
    FastIO() {
        srand(time(NULL));
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        cout.precision(12);
    };
} fastIO_;

template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template <typename T, size_t N>
inline ostream& operator<<(ostream& os, const array<T, N>& a) {
    os << "[";
    int cnt = 0;
    for (auto& val : a) {
        if (cnt++) os << ", ";
        os << val;
    }
    os << "]";
    return os;
}

template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    int cnt = 0;
    for (auto& val : v) {
        if (cnt++) os << ", ";
        os << val;
    }
    return os << "]";
}

template <typename T>
inline ostream& operator<<(ostream& os, const set<T>& v) {
    os << "{";
    int cnt = 0;
    for (auto& val : v) {
        if (cnt++)
            os << ", ";
        os << val;
    }
    return os << "}";
}

template <typename T>
inline ostream& operator<<(ostream& os, const multiset<T>& v) {
    os << "{";
    int cnt = 0;
    for (auto& val : v) {
        if (cnt++)
            os << ", ";
        os << val;
    }
    return os << "}";
}

template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const map<T1, T2>& v) {
    os << "[";
    int cnt = 0;
    for (auto& val : v) {
        if (cnt++)
            os << ", ";
        os << val;
    }
    return os << "]";
}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

// types
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define si set<int>
#define mpii map<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>

// names
#define pb push_back
#define fi first
#define se second
#define mp(a, b) make_pair((a), (b))
#define sz(a) ((int)(a).size())
#define rep(i, s, t) for (int i = (s); i < (t); i++)
#define repn(i, s) for (int i = 0; i < (s); i++)
#define ms(a, b) memset(a, b, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define bit(n, i) (((n) >> (i)) & 1)
#define bitCount(n) __builtin_popcountll((n))

// constants
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, 1, -1};

// functions
template <class T>
inline bool umin(T& a, const T b) { return b < a ? a = b, 1 : 0; }
template <class T>
inline bool umax(T& a, const T b) { return a < b ? a = b, 1 : 0; }
template <class T>
inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T>
inline T lcm(T a, T b) { return a / gcd(a, b) * b; }

// =====================================================================================================================

template <int MOD_>
struct modnum {
    typedef long long int64;

    static constexpr int MOD = MOD_;
    static_assert(MOD_ > 0, "MOD must be positive");

   public:
    int v;
    static int minv(int a, int m) {
        a %= m;
        assert(a);
        return a == 1 ? 1 : int(m - int64(minv(m, a)) * int64(m) / a);
    }

   public:
    modnum() : v(0){};
    modnum(int64 v_) : v(int(v_ % MOD)) {
        if (v < 0) v += MOD;
    }
    explicit operator int() const { return v; }
    friend std::ostream& operator<<(std::ostream& out, const modnum& n) { return out << int(n); }
    friend std::istream& operator>>(std::istream& in, modnum& n) {
        int64 v_;
        in >> v_;
        n = modnum(v_);
        return in;
    }
    friend bool operator==(const modnum& a, const modnum& b) { return a.v == b.v; }
    friend bool operator!=(const modnum& a, const modnum& b) { return a.v != b.v; }

    modnum inv() const {
        modnum res;
        res.v = minv(v, MOD);
        return res;
    }
    friend modnum inv(const modnum& m) { return m.inv(); }
    modnum neg() const {
        modnum res;
        res.v = v ? MOD - v : 0;
        return res;
    }
    friend modnum neg(const modnum& m) { return m.neg(); }

    modnum operator-() const { return neg(); }
    modnum operator+() const { return modnum(*this); }

    modnum& operator++() {
        ++v;
        if (v == MOD) v = 0;
        return *this;
    }
    modnum& operator--() {
        if (v == 0) v = MOD;
        --v;
        return *this;
    }
    modnum& operator+=(const modnum& o) {
        v += o.v;
        if (v >= MOD) v -= MOD;
        return *this;
    }
    modnum& operator-=(const modnum& o) {
        v -= o.v;
        if (v < 0) v += MOD;
        return *this;
    }
    modnum& operator*=(const modnum& o) {
        v = int(int64(v) * int64(o.v) % MOD);
        return *this;
    }
    modnum& operator/=(const modnum& o) { return *this *= o.inv(); }

    friend modnum operator++(modnum& a, int) {
        modnum r = a;
        ++a;
        return r;
    }
    friend modnum operator--(modnum& a, int) {
        modnum r = a;
        --a;
        return r;
    }
    friend modnum operator+(const modnum& a, const modnum& b) { return modnum(a) += b; }
    friend modnum operator-(const modnum& a, const modnum& b) { return modnum(a) -= b; }
    friend modnum operator*(const modnum& a, const modnum& b) { return modnum(a) *= b; }
    friend modnum operator/(const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
// using mint = modnum<1000000007>;
using mint = modnum<998244353>;

struct SegmentTree {
#define N 200004
#define lson(id) (id << 1)
#define rson(id) ((id << 1) | 1)

    typedef mint type;
    struct Node {
        type add, sum;
        int l, r;
    } seg[N << 2];

    void build(int id, int l, int r) {
        seg[id].l = l;
        seg[id].r = r;
        seg[id].add = 0;
        if (l == r) {
            seg[id].sum = 0;
        } else {
            int mid = (l + r) >> 1;
            build(lson(id), l, mid);
            build(rson(id), mid + 1, r);
            seg[id].sum = seg[lson(id)].sum + seg[rson(id)].sum;
        }
    }

    void update(int id, int l, int r, type w) {
        if (seg[id].l == l && seg[id].r == r) {
            seg[id].add += w;
            seg[id].sum += w * (r - l + 1);
            return;
        }
        int mid = (seg[id].l + seg[id].r) >> 1;
        if (r <= mid)
            update(lson(id), l, r, w);
        else if (l > mid)
            update(rson(id), l, r, w);
        else {
            update(lson(id), l, mid, w);
            update(rson(id), mid + 1, r, w);
        }
        seg[id].sum = seg[lson(id)].sum + seg[rson(id)].sum;
    }
    type query(int id, int l, int r) {
        if (seg[id].l == l && seg[id].r == r) {
            return seg[id].sum;
        }
        if (seg[id].add.v > 0) {
            seg[lson(id)].add += seg[id].add;
            seg[lson(id)].sum += seg[id].add * (seg[lson(id)].r - seg[lson(id)].l + 1);
            seg[rson(id)].add += seg[id].add;
            seg[rson(id)].sum += seg[id].add * (seg[rson(id)].r - seg[rson(id)].l + 1);
            seg[id].add = 0;
        }
        int mid = (seg[id].l + seg[id].r) >> 1;
        if (r <= mid)
            return query(lson(id), l, r);
        else if (l > mid)
            return query(rson(id), l, r);
        else
            return query(lson(id), l, mid) + query(rson(id), mid + 1, r);
    }
} st;

#define maxn 15
int n, m;
int l[maxn], r[maxn];

mint solve() {
    for (int i = 1; i <= m; i++) cin >> l[i] >> r[i];
    mint ans(0);

    st.build(1, 1, n);
    st.update(1, 1, 1, mint(1));

    for (int i = 1; i < n; i++) {
        mint val = st.query(1, i, i);
        // trace(i, val);
        for (int j = 1; j <= m; j++) {
            if (l[j] + i > n)
                continue;
            int l2 = min(l[j] + i, n);
            int r2 = min(r[j] + i, n);
            st.update(1, l2, r2, val);
            // trace(i, l2, r2, val);
        }
    }
    return st.query(1, n, n);
}

void solve(int _cas) {
    // solve();
    cout << solve() << endl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("C.in", "r", stdin);
#endif

    while (cin >> n >> m) solve(1);
}


Measured memory_bytes: 16164