using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = 998244353;
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class RangeSum
{
    int max;
    HashSet<(int l, int r, ModInt v)> ranges = new HashSet<(int l, int r, ModInt v)>();

    public RangeSum(int N)
    {
        max = N;
    }

    public void Add(int l, int r, int v)
    {
        ranges.Add((l, r, v));
    }

    public ModInt GetAndPurge(int i)
    {
        var v = new ModInt(0);
        foreach (var range in ranges.ToArray())
        {
            if (range.l <= i && i <= range.r)
            {
                v += range.v;
            }
            if(range.r <= i)
            {
                ranges.Remove(range);
            }
        }
        return v;
    }

    public void Distribute(int i, (int l, int r)[] nexts)
    {
        var v = GetAndPurge(i);
        if(v.Num == 0)
        {
            return;
        }
        foreach (var next in nexts)
        {
            var l = i + next.l;
            var r = i + next.r;
            if (l > max)
            {
                continue;
            }
            ranges.Add((l, r, v));
        }
    }
}

public static class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var K = vals[1];
        var ranges = new (int l, int r)[K];
        for (int i = 0; i < K; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            ranges[i] = (vals[0], vals[1]);
        }

        var sum = new RangeSum(N);
        sum.Add(1, 1, 1);

        for (int i = 1; i <  N; i++)
        {
            sum.Distribute(i, ranges);
        }

        Console.WriteLine(sum.GetAndPurge(N));
    }
}