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

typedef long long          ll;
typedef long double        ld;
typedef unsigned long long ull;
typedef vector<ll>         vl;
typedef vector<vl>         vvl;
typedef pair<ll,ll>        pll;
typedef vector<pll>        vpll;

#define ff          first
#define ss          second
#define mp          make_pair
#define mt          make_tuple
#define pb          push_back
#define eb          emplace_back
#define fr(i,n)     for(ll i = 0; i < n; ++i)
#define frs(i,s,n)  for(ll i = s; i < n; ++i)
#define frb(i,s,e)  for(ll i = s; i <= e; ++i)
#define rfr(i,n)    for(ll i = n-1; i >= 0; i--)
#define frbr(i,e,s) for(ll i = e; i >= s; i--)
#define all(x)      (x).begin(), (x).end()
#define sz(x)       ((ll)(x).size())

#ifdef LOCAL
#include </home/udaya_bhaskar/Desktop/debugger.h>
#else
#define dbg(x...)      {}
#define dbg_arr(a,n)   {}
#define dbg_mat(m,r,c) {}
#define dbg_time()     {}
#endif

const ll MOD  = 998244353;
const ll INF  = 1e18;
const ll MAX  = 100100;



template< const ll &mod >
struct modular 
{
    ll val;

    modular(ll v = 0) 
    {
        if (v < 0) v = v % mod + mod;
        if (v >= mod) v %= mod;
        val = v;
    }

    static ll inv_mod(ll a, ll m = mod) // Extended Euclidean algorithm
    {
        ll g = m, r = a, x = 0, y = 1;

        while (r != 0) 
        {
            ll q = g / r;
            g %= r; swap(g, r);
            x -= q * y; swap(x, y);
        }

        return x < 0 ? x + m : x;
    }

    modular& operator+=(const modular &other) 
    {
        val -= mod - other.val;
        if (val < 0) val += mod;
        return *this;
    }

    modular& operator-=(const modular &other) 
    {
        val -= other.val;
        if (val < 0) val += mod;
        return *this;
    }

    static unsigned fast_mod(ull x, unsigned m = mod) 
    {
        #if !defined(_WIN32) || defined(_WIN64)
                return unsigned(x % m);
        #endif
                // Optimized mod for Codeforces 32-bit machines.
                // x must be less than 2^32 * m for this to work, so that x / m fits in a 32-bit unsigned int.
                unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
                unsigned quot, rem;
                asm("divl %4\n"
                    : "=a" (quot), "=d" (rem)
                    : "d" (x_high), "a" (x_low), "r" (m));
                return rem;
    }

    modular& operator*=(const modular &other) 
    {
        val = fast_mod(ull(val) * other.val);
        return *this;
    }

    modular& operator/=(const modular &other) 
    {
        return *this *= other.inv();
    }

    friend modular operator+(const modular &a, const modular &b) { return modular(a) += b; }
    friend modular operator-(const modular &a, const modular &b) { return modular(a) -= b; }
    friend modular operator*(const modular &a, const modular &b) { return modular(a) *= b; }
    friend modular operator/(const modular &a, const modular &b) { return modular(a) /= b; }

    modular& operator++() 
    {
        val = val == mod - 1 ? 0 : val + 1;
        return *this;
    }

    modular& operator--() 
    {
        val = val == 0 ? mod - 1 : val - 1;
        return *this;
    }

    modular operator++(int) { modular before = *this; ++*this; return before; }
    modular operator--(int) { modular before = *this; --*this; return before; }

    modular operator-() const 
    {
        return val == 0 ? 0 : mod - val;
    }

    bool operator==(const modular &other) const { return val == other.val; }
    bool operator!=(const modular &other) const { return val != other.val; }

    modular inv() const 
    {
        return inv_mod(val);
    }

    modular pow(ll p) const 
    {
        if (p < 0)
            return inv().pow(-p);

        modular a = *this, result = 1;

        while (p > 0) 
        {
            if (p & 1)
                result *= a;

            p >>= 1;

            if (p > 0)
                a *= a;
        }

        return result;
    }

    explicit operator ll() const { return val; }

    friend ostream& operator<<(ostream &os, const modular &m) 
    {
        return os << m.val;
    }

    inline friend string to_string(modular x) {return to_string(ll(x));}
};

using mint = modular<MOD>;


void pre()
{
  // factorizer::sieve();
  // prepare_factorials();
}

#define LSOne(i) ((i) & -(i))

struct BIT
{
  ll N;
  vector < mint > T;

  void init(ll n)
  {
      this->N = n + 1;
      T.assign(N, mint(0));
  } 

  mint pref(ll i)
  {
      mint sum = 0; i++;
      while(i > 0)
      {
        sum += T[i];
        i -= LSOne(i);
      }
      return sum;
  }
  
  void add(ll i, mint val)
  {
      i++;
      while(i < N)
      {
        T[i] += val;
        i += LSOne(i);
      }
  }

  mint rsum(ll l, ll r)
  {
      return pref(r) - pref(l - 1);
  }
};


void solve()
{
  ll n, k; cin >> n >> k;
  BIT b1;
  b1.init(n);
  vpll rs;
  fr(i, k)
  {
  	ll x, y; cin >> x >> y;
    rs.eb(x, y);
  }
  b1.add(0, mint(1));
  fr(i, n)
  {
  	vpll poss;
  	for(auto x: rs)
  	  poss.eb(i - x.ss, i - x.ff);
  	for(auto x: poss)
  	{
  	  if(!(x.ff < 0 && x.ss < 0))
  	  {
        ll l = max(x.ff, 0LL);
        ll r = x.ss;
        b1.add(i, b1.rsum(l, r));
  	  }
  	}
  }
  cout << b1.rsum(n - 1, n - 1) << "\n";
}




signed main()
{  
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  // cout << fixed << setprecision(15);
  
  pre();

  ll t = 1;
  // cin >> t;
  frb(CASE, 1, t)
  {
    // cout << "Case #" << CASE << ": ";
    // dbg(CASE);
    solve();
  }

  dbg_time();
  
  return 0;
}     
     


Measured memory_bytes: 4708