using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    static int ResultCount = 0;
    static char[,] map;
    static int n;
    static int m;
    static void Main(string[] args)
    {
        string firstLine = Console.ReadLine();
        n = Convert.ToInt32(firstLine.Split(' ')[0]);
        m = Convert.ToInt32(firstLine.Split(' ')[1]);

        map = new char[n, m];
        for (int index = 0; index < n; index++)
        {
            string line = Console.ReadLine();
            for (int j = 0; j < m; j++)
            {
                map[index, j] = line[j];
            }
        }

        while (GetOne()) ;
        while (GetTwo()) ;
        Console.WriteLine(ResultCount);
    }

    static bool GetTwo()
    {
        int lastResultCount = ResultCount;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                char ch = map[i, j];
                if (ch == '.') { continue; }

                int count = 0;
                int i2 = i;
                int j2 = j;
                if (i != n - 1 && map[i + 1, j] != '.' && map[i + 1, j] != map[i, j])
                {
                    count++;
                    i2 = i + 1;
                    j2 = j;
                }
                if (i != 0 && map[i - 1, j] != '.' && map[i - 1, j] != map[i, j])
                {
                    count++;
                    i2 = i - 1;
                    j2 = j;
                }
                if (j != n - 1 && map[i, j + 1] != '.' && map[i, j + 1] != map[i, j])
                {
                    count++;
                    i2 = i;
                    j2 = j + 1;
                }
                if (j != 0 && map[i, j - 1] != '.' && map[i, j - 1] != map[i, j])
                {
                    count++;
                    i2 = i;
                    j2 = j - 1;
                }

                if (count == 2)
                {
                    ResultCount++;
                    map[i, j] = '.';
                    map[i, j + 1] = '.';
                    while (GetOne()) ;
                }
            }
        }
        return lastResultCount != ResultCount;
    }

    static bool GetOne()
    {
        int lastResultCount = ResultCount;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                char ch = map[i, j];
                if (ch == '.') { continue; }

                int count = 0;
                int i2 = i;
                int j2 = j;
                if (i != n - 1 && map[i + 1, j] != '.' && map[i + 1, j] != map[i, j])
                {
                    count++;
                    i2 = i + 1;
                    j2 = j;
                }
                if (i != 0 && map[i - 1, j] != '.' && map[i - 1, j] != map[i, j])
                {
                    count++;
                    i2 = i - 1;
                    j2 = j;
                }
                if (j != m - 1 && map[i, j + 1] != '.' && map[i, j + 1] != map[i, j])
                {
                    count++;
                    i2 = i;
                    j2 = j + 1;
                }
                if (j != 0 && map[i, j - 1] != '.' && map[i, j - 1] != map[i, j])
                {
                    count++;
                    i2 = i;
                    j2 = j - 1;
                }

                if (count == 1)
                {
                    ResultCount++;
                    map[i, j] = '.';
                    map[i2, j2] = '.';
                }
            }
        }
        return lastResultCount != ResultCount;
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class GFG
{

    public static void Main()
    {
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var m = int.Parse(input[1]);
        char[,] arr = new char[n, m];
        for (int i = 0; i < n; i++)
        {
            var chars = Console.ReadLine().ToCharArray();
            for (int j = 0; j < m; j++)
            {
                arr[i, j] = chars[j];
            }
        }
        bool[,] check = new bool[n, m];
        int count = 0;
        for (int i = 0; i < n; i++)
        {

            for (int j = 0; j < m; j++)
            {
                if (arr[i, j] == 'W')
                {
                    if (i-1 >= 0 && check[i - 1, j] == false && arr[i - 1, j] == 'P')
                    {
                        check[i - 1, j] = true;
                        count++;
                        continue;
                    }
                    if (j -1>= 0 && check[i, j - 1] == false && arr[i, j - 1] == 'P')
                    {
                        check[i, j - 1] = true;
                        count++;
                        continue;
                    }
                    if (i+1 <= n && check[i + 1, j] == false && arr[i + 1, j] == 'P')
                    {
                        check[i + 1, j] = true;
                        count++;
                        continue;
                    }
                    if (j+1 <= m && check[i, j + 1] == false && arr[i, j + 1] == 'P')
                    {
                        check[i, j + 1] = true;
                        count++;
                        continue;
                    }

                }
            }
        }

        Console.Write(count);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] y = Console.ReadLine().Split(' ');
            int[] a = new int[7];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = int.Parse(y[i]);
            }
            int nn = 0;
            while (n > 0)
            {
                n -= a[nn];
                nn++;
                if (nn == 8)
                    nn = 0;
            }
            Console.Write(nn);
        }
    }
}


using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.IO;

class Program
{
    class Point: IComparable<Point>
    {
        public int x, y;
        public Point(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        public int CompareTo(Point other)
        {
            if (other.x != x)
                return x - other.x;
            else
                return y - other.y;
        }
        public override bool Equals(object obj)
        {
            Point other = (Point)obj;
            return other.x == x && other.y == y;
        }
    }
    class Seg
    {
        public Point a, b;
        public Seg(Point a, Point b)
        {
            this.a = a;
            this.b = b;
        }
        public void revert()
        {
            Point temp = a;
            a = b;
            b = temp;
        }
    }
    void solve()
    {
        Seg[] seg = new Seg[4];
        for (int i = 0; i < 4; i++)
        {
            seg[i] = new Seg(new Point(nextInt(), nextInt()), new Point(nextInt(), nextInt()));
        }
        List<Seg> vertical = new List<Seg>();
        List<Seg> horizontal = new List<Seg>();
        foreach (Seg s in seg)
        {
            if (s.a.x == s.b.x)
            {
                vertical.Add(s);
            }
            else if (s.a.y == s.b.y)
            {
                horizontal.Add(s);
            }
            else
            {
                Console.WriteLine("NO");
                return;
            }
        }
        if (vertical.Count < 2 || horizontal.Count < 2)
        {
            Console.WriteLine("NO");
            return;
        }
        foreach (Seg s in vertical)
        {
            if (s.a.y > s.b.y)
                s.revert();
        }
        foreach (Seg s in horizontal)
        {
            if (s.a.x < s.b.y)
                s.revert();
        }
        int height1 = vertical[0].b.y - vertical[0].a.y;
        int height2 = vertical[1].b.y - vertical[1].a.y;
        int width1 = horizontal[0].b.x - horizontal[0].a.x;
        int width2 = horizontal[1].b.x - horizontal[1].a.x;
        if (height1 != height2 || width1 != width2 || height1==0 ||  width1==0)
        {
            Console.WriteLine("NO");
            return;
        }
        if (vertical[0].a.x > vertical[1].a.x)
        {
            Seg temp = vertical[0];
            vertical[0] = vertical[1];
            vertical[1] = temp;
        }
        if (horizontal[0].a.y > horizontal[1].a.y)
        {
            Seg temp = horizontal[0];
            horizontal[0] = horizontal[1];
            horizontal[1] = temp;
        }
        if (!vertical[0].a.Equals(horizontal[0].a))
        {
            Console.WriteLine("NO");
            return;
        }
        if (!vertical[0].b.Equals(horizontal[1].a))
        {
            Console.WriteLine("NO");
            return;
        }
        if (!vertical[1].a.Equals(horizontal[0].b))
        {
            Console.WriteLine("NO");
            return;
        }
        if (!vertical[1].b.Equals(horizontal[1].b))
        {
            Console.WriteLine("NO");
            return;
        }
        Console.WriteLine("YES");

    }

    //

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace codeforces
{
    class C
    {
        static CodeforcesUtils CF = new CodeforcesUtils(
@"
0 0 0 1
0 1 0 2
0 2 0 3
0 3 0 0
");

        static void Main(string[] args)
        {
            bool b = true;
            Dictionary<string, int> c = new Dictionary<string, int>();
            List<int> xs = new List<int>();
            List<int> ys = new List<int>();
            for (int i = 0;i<4;i++)
            {
                string[] ss  = CF.ReadLine().Split(' ');
                int x1 = int.Parse(ss[0]);
                int y1 = int.Parse(ss[1]);
                int x2 = int.Parse(ss[2]);
                int y2 = int.Parse(ss[3]);

                if (!_l(x1, y1, x2, y2))
                {
                    b = false;
                    break;
                }

                string p1 = x1 +","+ y1;
                if (!c.ContainsKey(p1))
                    c.Add(p1, 0);
                c[p1]++;

                string p2 = x2 + "," + y2;
                if (!c.ContainsKey(p2))
                    c.Add(p2, 0);
                c[p2]++;

                if( !xs.Contains(x1) )
                    xs.Add(x1);
                if (!xs.Contains(x2))
                    xs.Add(x2);
                if (!ys.Contains(y1))
                    ys.Add(y1);
                if (!ys.Contains(y2))
                    ys.Add(y2);
            }

            if (b)
            {
                if (xs.Count != 2 || ys.Count != 2)
                    b = false;
                else if (c.Count != 4)
                    b = false;
                else
                {
                    foreach (int v in c.Values)
                    {
                        if (v != 2)
                        {
                            b=false;
                            break;
                        }
                    }
                }
            }

            if (b)
                CF.WriteLine("YES");
            else
                CF.WriteLine("NO");

        }

        static bool _l(int x1,int y1,int x2,int y2)
        {
            if( x1!=x2&&y1!=y2)
                return false;
            if (x1 == x2 && y1 == y2)
                return false;
            return true;
        }

        #region test

        class CodeforcesUtils
        {
            public string ReadLine()
            {
#if DEBUG
                if (_lines == null)
                {
                    _lines = new List<string>();
                    string[] ss = _test_input.Replace("\n", "").Split('\r');
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if (
                            (i == 0 || i == ss.Length - 1) &&
                            ss[i].Length == 0
                            )
                            continue;

                        _lines.Add(ss[i]);
                    }
                }

                string s = null;
                if (_lines.Count > 0)
                {
                    s = _lines[0];
                    _lines.RemoveAt(0);
                }
                return s;
#else
            return Console.In.ReadLine();
#endif
            }

            public void WriteLine(object o)
            {
#if DEBUG
                System.Diagnostics.Trace.WriteLine(o);
#else
            Console.WriteLine(o);
#endif
            }

            public void Write(object o)
            {
#if DEBUG
                System.Diagnostics.Trace.Write(o);
#else
            Console.Write(o);
#endif
            }

            public CodeforcesUtils(string test_input)
            {
                _test_input = test_input;
            }

            string _test_input;

            List<string> _lines;
        }

        #endregion
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
public class CodeForces
{
#if TEST
    // To set this go to Project -> Properties -> Build -> General -> Conditional compilation symbols: -> enter 'TEST' into text box.
    const bool testing = true;
#else
const bool testing = false;
#endif

    static void program(TextReader input)
    {
       // var n = int.Parse(input.ReadLine());
        var data = input.ReadLine().Split(' ').Select(int.Parse).ToList();
        var l = data[0];
        var r = data[1];
        var a = data[2];
        var i = 200;
        for (; i > 0; i-=2)
        {
            var left = i / 2;
            var right = left;
            left -= l;
            right -= r;
            var need = 0;
            need = Math.Max(0, left) + Math.Max(0, right);
            if(need <= a)
            {
                break;
            }
        }

        Console.WriteLine(i);
    }

    public static void Main(string[] args)
    {
        if (!testing)
        { // set testing to false when submiting to codeforces
            program(Console.In); // write your program in 'program' function (its your new main !)
            return;
        }

        Console.WriteLine("Test Case(1) => expected :");
        Console.WriteLine("6\n");
        Console.WriteLine("Test Case(1) => found    :");
        program(new StringReader("1 4 2\n"));
        Console.WriteLine();

        Console.WriteLine("Test Case(2) => expected :");
        Console.WriteLine("14\n");
        Console.WriteLine("Test Case(2) => found    :");
        program(new StringReader("5 5 5\n"));
        Console.WriteLine();

        Console.WriteLine("Test Case(3) => expected :");
        Console.WriteLine("0\n");
        Console.WriteLine("Test Case(3) => found    :");
        program(new StringReader("0 2 0\n"));
        Console.WriteLine();

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int Main(string[] args)
        {
            int K, L, i;
            //Read line, and split it by whitespace into an array of strings
            string[] tokens = Console.ReadLine().Split();

            //Parse element 0
            K = int.Parse(tokens[0]);

            //Parse element 1
            L = int.Parse(tokens[1]);

            for (i = 1; Math.Pow((double)K , (double)i) <= (double)L; i++)
            {
                double a = Math.Pow((double)K , (double)i);
                double b = (double)L;
                if (a == b)
                {
                    Console.WriteLine("YES\n{0}\n", i - 1);
                    return 0;
                }
            }
            Console.WriteLine("NO\n");
            return 0;
        }
    }
}


using System;
using System.Collections.Generic;

class Program
    {
        static void Main()
        {

            string[] arr = Console.ReadLine().Split();

            List<int> bets_list = arr.Select(int.Parse).ToList();
            int intial_bet_sum = 0;
            for(int i=0; i < bets_list.Count; i++)
            {
                intial_bet_sum += bets_list[i];
            }
            //decimal bet = intial_bet_sum / bets_list.Count;
            //double b = intial_bet_sum / bets_list.Count;

            if ((intial_bet_sum % bets_list.Count) == 0)
            {
                Console.WriteLine(intial_bet_sum / bets_list.Count);
            }
            else
            {
                Console.WriteLine(-1);
            }

        }

    }


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    long Fun(long a, long b, long x)
    {
        if (b > x)
            return 0;
        return (x - b) / a + 1;
    }

    long Fun(long a, long b, long l, long r)
    {
        return Fun(a, b, r) - Fun(a, b, l - 1);
    }

    long Gcd(long a, long b, out long x, out long y)
    {
        if (a == 0)
        {
            x = 0;
            y = 1;
            return b;
        }
	    long x1, y1;
	    long d = Gcd(b % a, a, out x1, out y1);
	    x = y1 - (b / a) * x1;
	    y = x1;
	    return d;
    }

    bool Dio(long a, long b, long c, out long x0, out long y0, out long g)
    {
	    g = Gcd(Math.Abs(a), Math.Abs(b), out x0, out y0);
	    if (c % g != 0)
		    return false;
	    x0 *= c / g;
	    y0 *= c / g;
	    if (a < 0)
            x0 *= -1;
	    if (b < 0)
            y0 *= -1;
	    return true;
    }

    public void Solve()
    {
        long a1 = ReadInt();
        long b1 = ReadInt();
        long a2 = ReadInt();
        long b2 = ReadInt();
        long l = ReadInt();
        long r = ReadInt();

        if (a1 == a2)
        {
            if (Math.Abs(b1 - b2) % a1 != 0)
                Write(0);
            else
                Write(Fun(a1, Math.Max(b1, b2), l, r));
            return;
        }

        long x0, y0, g;
        if (!Dio(a1, -a2, b2 - b1, out x0, out y0, out g))
        {
            Write(0);
            return;
        }

        long d = a2 / g;
        if (x0 < 0)
            x0 += ((-x0 - 1) / d + 1) * d;
        x0 %= d;
        Write(Fun(d * a1, a1 * x0 + b1, l, r));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }
            if (hours.Length==1&& minutes.Length==1)
            {
                Console.WriteLine(-1); return;
            }

            int basesC = 0;
            List<int> bases = new List<int>();

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);
            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {
                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            int basesC = 0;
            List<int> bases = new List<int>();

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }
            if (GetDigits(initbase, 59) > arr[1].Length)
            {
                Console.WriteLine(0); return;
            }
            if (hours.Length <= 1 && minutes.Length <= 1)
            {

                Console.WriteLine(-1); return;
            }
            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

public class C
{
    public static void Main()
    {
        var nms = Console.ReadLine().Split(' ').Select(str=>long.Parse(str)).ToArray();
        long n = nms[0], m = nms[1], s = nms[2];
        Console.WriteLine(Math.Min(m, s)*Math.Min(n, s));
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace CodeForcesApp
{
    class C
    {
        #region Shortcuts
        static string RL() { return Console.ReadLine(); }
        static string[] RSA() { return RL().Split(' '); }
        static int[] RIA() { return Array.ConvertAll<string, int>(RSA(), int.Parse); }
        static int RInt() { return int.Parse(RL()); }
        static long RLong() { return long.Parse(RL()); }
        static double RDouble() { return double.Parse(RL()); }
        static void RInts2(out int p1, out int p2) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; }
        static void RInts3(out int p1, out int p2, out int p3) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; }

        static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
        static void Fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }
        static void Fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }
        #endregion

        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            //SolutionTester tester = new SolutionTester(CodeForcesTask.C);
            //tester.Test();

            Task task = new Task();
            task.Solve();
        }

        public class Task
        {

            public void Solve()
            {
                int n, m, s;
                RInts3(out n, out m, out s);

                int nmax = 1 + (n - 1) / s;
                int mmax = 1 + (m - 1) / s;

                int n1 = 0;
                int m1 = 0;

                for (int i = 0; i < n; i++)
                    if (1 + i / s + (n - i - 1) / s == nmax)
                        n1++;

                for (int i = 0; i < m; i++)
                    if (1 + i / s + (m - i - 1) / s == mmax)
                        m1++;

                Console.WriteLine(n1 * m1);
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace run
{
    class Program
    {
        private static int Swap(ref int a, ref int b)
        {
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            return 0;
        }

        private static int gcd(int a, int b)
        {
            Swap(ref a, ref b);

            while (a % b != 0)
            {
                a %= b;
                Swap(ref a, ref b);
            }

            return b;

        }

        private static void Main(string[] args)
        {

            var nstr = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            int a = nstr[0], b = nstr[1], c = nstr[2], d = nstr[3];

            if (c < d)
            {
                Swap(ref c, ref d);
                int tmp = a;
                a = b;
                b = tmp;
            }

                int lcm = a * c / gcd(a, c);

                b = b * (lcm / a);
                //a = lca;
                d = d * (lcm / c);
                //c = lca;

            int p = Math.Max(b, d);
                int q = Math.Abs(b - d);

                if (q == 0) while (true) q = 0;

            //Swap(ref p, ref q);

            for (int i = 2; i <= q; ++i)
                {
                    if (p % i == 0 && q % i == 0)
                    {
                        p /= i;
                        q /= i;
                        i--;
                    }
                }

            Console.WriteLine("{0}/{1}", q, p);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static int[] ReadInt(int size)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] res = new int[size];
            for (int i=0; i<input.Length; i++)
            {
                res[i] = Convert.ToInt32(input[i]);
            }
            return res;
        }

        static int ReadInt()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            return n;
        }

        static String ReadString()
        {
            return Console.ReadLine();
        }

        static int Max(int a, int b)
        {
            return (a > b ? a : b);
        }

        static void Main(string[] args)
        {
            String input = ReadString();
            bool[] a = new bool[100];
            int res = 0;
            foreach (Char ch in input)
            {
                if (!a[ch])
                {
                    res++;
                    a[ch] = true;
                }
            }
            if (res%2==0)
            {
                Console.WriteLine("CHAT WITH HER!");
            }
            else
            {
                Console.WriteLine("IGNORE HIM!");
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round62
{
    class C
    {
        static int n;
        static int[] fuel;
        static List<int[]>[] xs;
        static int f,c;

        static void chk(int cost)
        {
            if (fuel[n - 1] < 0) return;
            if (f == fuel[n - 1] && c < cost) { c = cost; }
            if (f == -1 || f > fuel[n - 1]) { f = fuel[n - 1]; c = cost; }
        }

        static void dfs(int i, int j, int cost)
        {
            if (i >= n - 1) { chk(cost); return; }
            if (j >= xs[i].Count) { if(fuel[i] == 0) dfs(i + 1, 0, cost); return; }
            int dst = xs[i][j][1];
            for (int k = 0; k <= 5; k++)
                if (k <= fuel[i] && xs[i][j][2] <= k && k <= xs[i][j][3])
                {
                    fuel[i] -= k;
                    fuel[dst] += k;

                    int nc = k == 0 ? cost : (cost + k * k + xs[i][j][4]);
                    dfs(i, j + 1, nc);

                    fuel[dst] -= k;
                    fuel[i] += k;
                }
        }

        public static void Main()
        {
            n = int.Parse(Console.ReadLine());
            xs = new List<int[]>[n];
            fuel = new int[n];
            for (int i = 0; i < n; i++)
                xs[i] = new List<int[]>();
            for (int i = 0; i < n * (n - 1) / 2; i++)
            {
                var ys = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
                ys[0]--; ys[1]--;
                xs[ys[0]].Add(ys);
            }
            f = -1; c = -1;
            for (int i = 0; i <= 5; i++)
            {
                fuel[0] = i;
                dfs(0, 0, 0);
            }
            Console.WriteLine("{0} {1}", f, c);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round62
{
    class C
    {
        static int n;
        static int[] fuel;
        static List<int[]>[] xs;
        static int f,c;

        static void chk(int cost)
        {
            if (fuel[n - 1] < 0) return;
            if (f == fuel[n - 1] && c < cost) { c = cost; }
            if (f == -1 || f > fuel[n - 1]) { f = fuel[n - 1]; c = cost; }
        }

        static void dfs(int i, int j, int cost)
        {
            if (i >= n - 1) { chk(cost); return; }
            if (j >= xs[i].Count)
            {
                if (i == 0 || fuel[i] == 0)
                    dfs(i + 1, 0, cost);
                return;
            }

            int dst = xs[i][j][1];
            for (int k = 0; k <= 5; k++)
                if (i == 0 || k <= fuel[i])
                    if (xs[i][j][2] <= k && k <= xs[i][j][3])
                    {
                        fuel[i] -= k;
                        fuel[dst] += k;

                        int nc = k == 0 ? cost : (cost + k * k + xs[i][j][4]);
                        dfs(i, j + 1, nc);

                        fuel[dst] -= k;
                        fuel[i] += k;
                    }
        }

        public static void Main()
        {
            n = int.Parse(Console.ReadLine());
            xs = new List<int[]>[n];
            fuel = new int[n];
            for (int i = 0; i < n; i++)
                xs[i] = new List<int[]>();
            for (int i = 0; i < n * (n - 1) / 2; i++)
            {
                var ys = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
                ys[0]--; ys[1]--;
                xs[ys[0]].Add(ys);
            }
            f = -1; c = -1;
            dfs(0, 0, 0);
            Console.WriteLine("{0} {1}", f, c);
        }
    }
}


using System;

namespace ConsoleApplication4
{
    class Program
    {
        struct Matrix
        {
            public long A1, A2, A3, A4;

            public static Matrix Mul(Matrix m1, Matrix m2)
            {
                Matrix result = new Matrix();
                result.A1 = m1.A1 * m2.A1 + m1.A2 * m2.A3;
                result.A2 = m1.A1 * m2.A2 + m1.A2 * m2.A4;
                result.A3 = m1.A3 * m2.A1 + m1.A4 * m2.A3;
                result.A4 = m1.A3 * m2.A2 + m1.A4 * m2.A4;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(int power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.Mul(result, modLast);

                        result.Mod(mod);
                    }

                    modLast = Matrix.Mul(modLast, modLast);
                    modLast.Mod(mod);
                    power >>= 1;
                }

                return result;
            }
        }

        static void Main(string[] args)
        {
            string[] fStrings = new string[41];
            fStrings[0] = "a"; fStrings[1] = "b";

            for (int i = 2; i < fStrings.Length; i++)
                fStrings[i] = fStrings[i - 1] + fStrings[i - 2];

            string[] inputStr = Console.ReadLine().Split(' ');
            int m = Convert.ToInt32(inputStr[0]);
            int n = Convert.ToInt32(inputStr[1]);

            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                long count = CalCount(s, fStrings, m - 1);
                Console.WriteLine(count % 1000000007);
            }
        }

        static long CalCount(string s, string[] fStrings, int f)
        {
            if (f < 16)
                return ContainCount(s, fStrings[f]);

            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            int[] result = new int[fStrings.Length];

            for (int i = 0; i < fStrings.Length; i++)
            {
                if (fStrings[i].Length > s.Length)
                    result[i] = ContainCount(s, fStrings[i]);

                if (fStrings[i].Length > s.Length * 10)
                    break;
            }

            int index = Array.IndexOf(result, 1);
            if (index < 0)
                return 0;

            if (result[index + 1] == 1)
                index++;

            Matrix power = Matrix.PowerMod(f - index + 1, m, 1000000007);

            if (result[index + 1] == 2)
            {
                if (result[index + 2] == 3)
                    return power.A2;
                else
                    return power.A1 - 1;
            }
            else
                return power.A1 - (f - index) % 2;
        }

        static int ContainCount(string p, string s)
        {
            int k = -1;
            int count = 0;

            while (true)
            {
                k = s.IndexOf(p, k + 1);
                if (k == -1) break;
                count++;
            }

            return count;
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace ConsoleApplication4
{
    class Program
    {
        struct Matrix
        {
            public long A1, A2, A3, A4;

            public static Matrix Mul(Matrix m1, Matrix m2)
            {
                Matrix result = new Matrix();
                result.A1 = m1.A1 * m2.A1 + m1.A2 * m2.A3;
                result.A2 = m1.A1 * m2.A2 + m1.A2 * m2.A4;
                result.A3 = m1.A3 * m2.A1 + m1.A4 * m2.A3;
                result.A4 = m1.A3 * m2.A2 + m1.A4 * m2.A4;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(int power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.Mul(result, modLast);

                        result.Mod(mod);
                    }

                    modLast = Matrix.Mul(modLast, modLast);
                    modLast.Mod(mod);
                    power >>= 1;
                }

                return result;
            }
        }

        static void Main(string[] args)
        {
            string[] fStrings = new string[31];
            fStrings[0] = "a"; fStrings[1] = "b";

            for (int i = 2; i < fStrings.Length; i++)
                fStrings[i] = fStrings[i - 1] + fStrings[i - 2];

            string[] inputStr = Console.ReadLine().Split(' ');
            int m = Convert.ToInt32(inputStr[0]);
            int n = Convert.ToInt32(inputStr[1]);
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                long count = CalCount(s, fStrings, m - 1);
                sw.WriteLine(count % 1000000007);
            }

            sw.Flush();
        }

        static long CalCount(string s, string[] fStrings, int f)
        {
            if (f < 10)
                return ContainCount(s, fStrings[f]);

            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            List<int> result = new List<int>();
            int index = 0;

            for (int i = 0; i < fStrings.Length; i++)
            {
                int count = ContainCount(s, fStrings[i]);
                if (count > 1)
                {
                    if(index == 0)
                        index = i;

                    result.Add(count);
                }

                if (fStrings[i].Length > s.Length * 10)
                    break;
            }

            if(result.Count == 0)
                return 0;

            index -= 2;
            Matrix power = Matrix.PowerMod(f - index + 1, m, 1000000007);

            if (result[0] == 2)
            {
                if (result[1] == 3)
                    return power.A2;
                else
                    return power.A1 - 1;
            }
            else
                return power.A1 - (f - index) % 2;
        }

        static int ContainCount(string p, string s)
        {
            if (p.Length > s.Length) return 0;
            int k = -1, count = 0;

            while (true)
            {
                k = s.IndexOf(p, k + 1);
                if (k == -1) break;
                count++;
            }

            return count;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round70
{
    class E
    {
        static int t,n;
        static int[,] dist, dist2;
        static string[] b1, b2;

        static void bfs(int x, int y, bool chk)
        {
            int[] dx = new int[4] { 1, 0, -1, 0 },
                  dy = new int[4] { 0, -1, 0, 1 };
            bool[,] visited = new bool[n, n];
            Queue<int> q = new Queue<int>();
            q.Enqueue(x * n + y);
            visited[x, y] = true;
            for (int a = 0; a < n; a++)
                for (int b = 0; b < n; b++)
                    dist[a, b] = 100000;
            dist[x, y] = 0;
            while (q.Any())
            {
                int v = q.Dequeue();
                x = v / n; y = v % n;
                for (int i = 0; i < 4; i++)
                    if (InRange(x + dx[i]) && InRange(y + dy[i]))
                    {
                        int d = dist[x, y] + 1;
                        if (visited[x + dx[i], y + dy[i]] || d > t)
                        {
                            continue;
                        }
                        visited[x + dx[i], y + dy[i]] = true;
                        if (!chk)
                        {
                            dist[x + dx[i], y + dy[i]] = d;
                            q.Enqueue((x + dx[i]) * n + (y + dy[i]));
                        }
                        else
                        {
                            char b = b2[y + dy[i]][x + dx[i]];
                            if (!char.IsDigit(b1[y + dy[i]][x + dx[i]]))
                            {
                                dist[x + dx[i], y + dy[i]] = d;
                            }
                            else if (d < dist2[x + dx[i], y + dy[i]])
                            {
                                q.Enqueue((x + dx[i]) * n + (y + dy[i]));
                                dist[x + dx[i], y + dy[i]] = d;
                            }
                            else if ('0' <= b && b <= '9' && d == dist2[x + dx[i], y + dy[i]])
                                dist[x + dx[i], y + dy[i]] = d;
                        }
                    }
            }
        }

        static bool InRange(int v) { return 0 <= v && v < n; }

        public static void Main()
        {
            var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
            n = xs[0];
            t = xs[1];
            dist = new int[n, n];
            b1 = new string[n];
            b2 = new string[n];
            for (int y = 0; y < n; y++)
                b1[y] = Console.ReadLine();
            Console.ReadLine();
            for (int y = 0; y < n; y++)
                b2[y] = Console.ReadLine();
            Dinic dinic = new Dinic(2000);
            int scnt = 2;
            for (int y = 0; y < n; y++)
                for (int x = 0; x < n; x++)
                    if (b1[y][x] == 'Z')
                    {
                        bfs(x,y,false);
                        dist2 = (int[,])dist.Clone();
                    }
            for (int y = 0; y < n; y++)
                for (int x = 0; x < n; x++)
                {
                    if ('1' <= b1[y][x] && b1[y][x] <= '9')
                    {
                        //Console.WriteLine("check {0} {1}", x, y);
                        bfs(x, y, true);
                        int scientists = b1[y][x] - '0';
                        for (int j = 0; j < scientists; j++)
                            dinic.AddEdge(0, scnt + j, 1);
                        int idx = 1000;
                        for (int a = 0; a < n; a++)
                            for (int b = 0; b < n; b++)
                                if ('1' <= b2[a][b] && b2[a][b] <= '9')
                                {
                                    int cnt = b2[a][b] - '0';
                                    for (int i = 0; i < cnt; i++, idx++)
                                        if (dist[b, a] < 100000)
                                        {
                                            //Console.WriteLine("{0} {1} -> {2} {3}", x, y, b, a);
                                            for (int j = 0; j < scientists; j++)
                                                dinic.AddEdge(scnt + j, idx, 1);
                                        }
                                }
                        scnt += scientists;
                    }
                }
            for (int y = 0, k = 1000; y < n; y++)
                for (int x = 0; x < n; x++)
                    if ('1' <= b2[y][x] && b2[y][x] <= '9')
                    {
                        int cnt = b2[y][x] - '0';
                        for (int i = 0; i < cnt; i++, k++)
                            dinic.AddEdge(k, 1, 1);
                    }
            Console.WriteLine(dinic.BipartiteMatching(0,1));
        }

        #region MaximumFlow
        class Dinic
        {
            const int INF = 1 << 29;

            class Edge
            {
                public int to, cap, rev;
                public Edge(int to_, int cap_, int rev_) { to = to_; cap = cap_; rev = rev_; }
            }

            List<Edge>[] G;
            int[] level, iter;

            void bfs(int s)
            {
                for (int i = 0; i < level.Length; i++) level[i] = -1;
                Queue<int> q = new Queue<int>();
                level[s] = 0;
                q.Enqueue(s);
                while (q.Count > 0)
                {
                    int v = q.Dequeue();
                    for (int i = 0; i < G[v].Count; i++)
                    {
                        Edge e = G[v][i];
                        if (e.cap > 0 && level[e.to] < 0)
                        {
                            level[e.to] = level[v] + 1;
                            q.Enqueue(e.to);
                        }
                    }
                }
            }

            int dfs(int v, int t, int f)
            {
                if (v == t) return f;
                for (int i = iter[v]; i < G[v].Count; i++, iter[v]++)
                {
                    Edge e = G[v][i];
                    if (e.cap > 0 && level[v] < level[e.to])
                    {
                        int d = dfs(e.to, t, Math.Min(f, e.cap));
                        if (d > 0)
                        {
                            e.cap -= d;
                            G[e.to][e.rev].cap += d;
                            return d;
                        }
                    }
                }
                return 0;
            }

            public void AddEdge(int from, int to, int cap)
            {
                G[from].Add(new Edge(to, cap, G[to].Count));
                G[to].Add(new Edge(from, 0, G[from].Count - 1));
            }

            public int MaxFlow(int s, int t)
            {
                int flow = 0;
                for (; ; )
                {
                    bfs(s);
                    if (level[t] < 0) return flow;
                    for (int i = 0; i < iter.Length; i++) iter[i] = 0;
                    for (int f = 0; (f = dfs(s, t, INF)) > 0; )
                        flow += f;
                }
            }

            public int BipartiteMatching(int s, int t)
            {
                return MaxFlow(s, t);
            }

            public Dinic(int size)
            {
                level = new int[size];
                iter = new int[size];
                G = new List<Edge>[size];
                for (int i = 0; i < size; i++)
                    G[i] = new List<Edge>();
            }
        }
        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round70
{
    class E
    {
        static int t,n;
        static int[,] dist, dist2;
        static string[] b1, b2;

        const int INF = 100000;

        static void bfs(int x, int y, bool chk)
        {
            int[] dx = new int[4] { 1, 0, -1, 0 },
                  dy = new int[4] { 0, -1, 0, 1 };
            bool[,] visited = new bool[n, n];
            Queue<int> q = new Queue<int>();
            q.Enqueue(x * n + y);
            visited[x, y] = true;
            for (int a = 0; a < n; a++)
                for (int b = 0; b < n; b++)
                    dist[a, b] = INF;
            dist[x, y] = 0;
            while (q.Any())
            {
                int v = q.Dequeue();
                x = v / n; y = v % n;
                for (int i = 0; i < 4; i++)
                    if (InRange(x + dx[i]) && InRange(y + dy[i]))
                    {
                        int d = dist[x, y] + 1;
                        if (visited[x + dx[i], y + dy[i]] || d > t)
                        {
                            continue;
                        }
                        visited[x + dx[i], y + dy[i]] = true;
                        if (!chk)
                        {
                            dist[x + dx[i], y + dy[i]] = d;
                            if (char.IsDigit(b1[y + dy[i]][x + dx[i]]))
                                q.Enqueue((x + dx[i]) * n + (y + dy[i]));
                        }
                        else
                        {
                            char b = b2[y + dy[i]][x + dx[i]];
                            if (d < dist2[x + dx[i], y + dy[i]])
                            {
                                q.Enqueue((x + dx[i]) * n + (y + dy[i]));
                                dist[x + dx[i], y + dy[i]] = d;
                            }
                            else if ('0' <= b && b <= '9' && d == dist2[x + dx[i], y + dy[i]])
                                dist[x + dx[i], y + dy[i]] = d;
                        }
                    }
            }
        }

        static bool InRange(int v) { return 0 <= v && v < n; }

        public static void Main()
        {
            var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
            n = xs[0];
            t = xs[1];
            dist = new int[n, n];
            b1 = new string[n];
            b2 = new string[n];
            for (int y = 0; y < n; y++)
                b1[y] = Console.ReadLine();
            Console.ReadLine();
            for (int y = 0; y < n; y++)
                b2[y] = Console.ReadLine();
            Dinic dinic = new Dinic(2000);
            int scnt = 2;
            for (int y = 0; y < n; y++)
                for (int x = 0; x < n; x++)
                    if (b1[y][x] == 'Z')
                    {
                        bfs(x,y,false);
                        dist2 = (int[,])dist.Clone();
                    }
            for (int y = 0; y < n; y++)
                for (int x = 0; x < n; x++)
                {
                    if (!('1' <= b1[y][x] && b1[y][x] <= '9'))
                        continue;
                    bfs(x, y, true);
                    int scientists = b1[y][x] - '0';
                    for (int j = 0; j < scientists; j++)
                        dinic.AddEdge(0, scnt + j, 1);
                    int idx = 1000;
                    for (int a = 0; a < n; a++)
                        for (int b = 0; b < n; b++)
                        {
                            if (!('1' <= b2[a][b] && b2[a][b] <= '9'))
                                continue;
                            int cnt = b2[a][b] - '0';
                            for (int i = 0; i < cnt; i++, idx++)
                                if (dist[b, a] < INF)
                                {
                                    //Console.WriteLine("{0} {1} -> {2} {3}", x, y, b, a);
                                    for (int j = 0; j < scientists; j++)
                                        dinic.AddEdge(scnt + j, idx, 1);
                                }
                        }
                    scnt += scientists;
                }
            for (int y = 0, k = 1000; y < n; y++)
                for (int x = 0; x < n; x++)
                    if ('1' <= b2[y][x] && b2[y][x] <= '9')
                    {
                        int cnt = b2[y][x] - '0';
                        for (int i = 0; i < cnt; i++, k++)
                            dinic.AddEdge(k, 1, 1);
                    }
            Console.WriteLine(dinic.BipartiteMatching(0,1));
        }

        #region MaximumFlow
        class Dinic
        {
            const int INF = 1 << 29;

            class Edge
            {
                public int to, cap, rev;
                public Edge(int to_, int cap_, int rev_) { to = to_; cap = cap_; rev = rev_; }
            }

            List<Edge>[] G;
            int[] level, iter;

            void bfs(int s)
            {
                for (int i = 0; i < level.Length; i++) level[i] = -1;
                Queue<int> q = new Queue<int>();
                level[s] = 0;
                q.Enqueue(s);
                while (q.Count > 0)
                {
                    int v = q.Dequeue();
                    for (int i = 0; i < G[v].Count; i++)
                    {
                        Edge e = G[v][i];
                        if (e.cap > 0 && level[e.to] < 0)
                        {
                            level[e.to] = level[v] + 1;
                            q.Enqueue(e.to);
                        }
                    }
                }
            }

            int dfs(int v, int t, int f)
            {
                if (v == t) return f;
                for (int i = iter[v]; i < G[v].Count; i++, iter[v]++)
                {
                    Edge e = G[v][i];
                    if (e.cap > 0 && level[v] < level[e.to])
                    {
                        int d = dfs(e.to, t, Math.Min(f, e.cap));
                        if (d > 0)
                        {
                            e.cap -= d;
                            G[e.to][e.rev].cap += d;
                            return d;
                        }
                    }
                }
                return 0;
            }

            public void AddEdge(int from, int to, int cap)
            {
                G[from].Add(new Edge(to, cap, G[to].Count));
                G[to].Add(new Edge(from, 0, G[from].Count - 1));
            }

            public int MaxFlow(int s, int t)
            {
                int flow = 0;
                for (; ; )
                {
                    bfs(s);
                    if (level[t] < 0) return flow;
                    for (int i = 0; i < iter.Length; i++) iter[i] = 0;
                    for (int f = 0; (f = dfs(s, t, INF)) > 0; )
                        flow += f;
                }
            }

            public int BipartiteMatching(int s, int t)
            {
                return MaxFlow(s, t);
            }

            public Dinic(int size)
            {
                level = new int[size];
                iter = new int[size];
                G = new List<Edge>[size];
                for (int i = 0; i < size; i++)
                    G[i] = new List<Edge>();
            }
        }
        #endregion
    }
}


#include <stdio.h>
#include<vector>
#include<iostream>
typedef long long int ll;

constexpr ll Mod = (119 << 23) + 1;
constexpr int E = 23;
constexpr ll O = 31;
constexpr ll InvO = 128805723;

ll Z[E + 1], InvZ[E + 1];

void Init() {
	Z[E] = O;
	InvZ[E] = InvO;
	for (int i = E - 1; i >= 0; i--) {
		Z[i] = (Z[i + 1] * Z[i + 1]) % Mod;
		InvZ[i] = (InvZ[i + 1] * InvZ[i + 1]) % Mod;
	}
}

ll Pow(ll x, ll y) {
	ll result = 1;
	while (y > 0)
	{
		if (y % 2 == 1) {
			result *= x;
			result %= Mod;
		}
		x *= x;
		x %= Mod;
		y /= 2;
	}

	return result;
}

ll Inv(ll x) {
	return Pow(x, Mod - 2);
}

// d桁のvを逆順にする
int bits_rev(int v, int d)
{
	int result = 0;
	for (int i = 0; i < d; i++) {
		if ((v & (1 << i))) result |= 1 << (d - i - 1);
	}
	return result;
}

void Transform(std::vector<ll>& a, int len, int lg, bool inverse) {
	for (int i = 0; i < len; i++) {
		int rev = bits_rev(i, lg);
		if (i >= rev) continue;
		ll t = a[i];
		a[i] = a[rev];
		a[rev] = t;
	}

	for (int i = 1; i <= lg; i++) {
		int b = 1 << (i - 1);
		ll z = 1;
		for (int j = 0; j < b; j++) {
			for (int k = j; k < len; k += (b << 1)) {
				ll t = (z * a[k + b]) % Mod;
				ll u = a[k];
				a[k] = (u + t) % Mod;
				a[k + b] = (u - t) % Mod;
				if (a[k + b] < 0) a[k + b] += Mod;
			}
			z *= inverse ? InvZ[i] : Z[i];
			z %= Mod;
		}
	}
}

void Convolution(std::vector<ll>& a, std::vector<ll> b, bool eq) {
	int sz = a.size() + b.size() - 1;
	int len = 1;
	int lg = 0;
	while (len < sz)
	{
		lg++;
		len *= 2;
	}

	a.resize(len);
	Transform(a, len, lg, false);

	if (eq) {
		for (int i = 0; i < len; i++) {
			a[i] *= a[i];
			a[i] %= Mod;
		}
	}
	else {
		b.resize(len);
		Transform(b, len, lg, false);
		for (int i = 0; i < len; i++) {
			a[i] *= b[i];
			a[i] %= Mod;
		}
	}

	Transform(a, len, lg, true);

	ll inv = Inv(len);

	for (int i = 0; i < sz; i++) {
		a[i] *= inv;
		a[i] %= Mod;
	}
	a.resize(sz);
}

int main(void) {
	Init();

	int n, k;
	scanf("%d %d", &n, &k);
	std::vector<ll> f;
	f.resize(1);
	f[0] = 1;

	std::vector<ll> t;
	t.resize(10);
	for (int i = 0; i < k; i++) {
		int d;
		scanf("%d", &d);
		t[d] = 1;
	}

	int h = n / 2;
	while (h > 0)
	{
		if (h % 2 == 1) {

			Convolution(f, t, false);
		}
		Convolution(t, t, true);
		h /= 2;
	}

	ll ans = 0;
	for (int i = 0; i < f.size(); i++) {
		ans += (f[i] * f[i]) % Mod;
		ans %= Mod;
	}

	printf("%lld", ans);
	return 0;
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using CompLib.Mathematics;
using CompLib.Util;

public class Program
{
    private const int MaxLg = 20;

    private int N, K;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();

        ModInt[] a = new ModInt[1];
        a[0] = 1;

        ModInt[] b = new ModInt[10];
        int min = int.MaxValue;
        int max = int.MinValue;
        for (int i = 0; i < K; i++)
        {
            int d = sc.NextInt();
            min = Math.Min(min, d);
            max = Math.Max(max, d);
            b[d] = 1;
        }

        int h = N / 2;
        int tmp = h;
        while (tmp > 0)
        {
            if ((tmp & 1) > 0)
            {
                FFT.Convolusion(ref a, b);
            }

            FFT.Convolusion(ref b);

            tmp >>= 1;
        }

        ModInt ans = 0;
        for (int i = min * h; i <= max * h; i++)
        {
            ans += a[i] * a[i];
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

static class FFT
{
    private const int E = 23;
    private const int MaxLg = 21;
    private static readonly ModInt O = 31;

    private static readonly ModInt[] Z, InvZ;

    private static readonly List<(int f, int t)>[] Rev;
    private static readonly ModInt[] InvLen;

    static FFT()
    {
        Z = new ModInt[E + 1];
        InvZ = new ModInt[E + 1];
        Z[E] = O;
        InvZ[E] = ModInt.Inverse(O);

        for (int i = E - 1; i >= 0; i--)
        {
            Z[i] = Z[i + 1] * Z[i + 1];
            InvZ[i] = InvZ[i + 1] * InvZ[i + 1];
        }

        Rev = new List<(int f, int t)>[MaxLg + 1];
        for (int i = 0; i <= MaxLg; i++)
        {
            int len = 1 << i;
            Rev[i] = new List<(int f, int t)>();
            for (int j = 0; j < len; j++)
            {
                int r = BitsReverse(j, i);
                if (j < r) Rev[i].Add((j, r));
            }
        }

        InvLen = new ModInt[MaxLg + 1];
        for (int i = 0; i <= MaxLg; i++)
        {
            InvLen[i] = ModInt.Inverse(1 << i);
        }
    }

    public static void Transform(ModInt[] a, int lg, int len, bool inverse)
    {
        foreach (var pair in Rev[lg])
        {
            var t = a[pair.f];
            a[pair.f] = a[pair.t];
            a[pair.t] = t;
        }

        for (int i = 1; i <= lg; i++)
        {
            int b = 1 << (i - 1);
            ModInt z = 1;
            for (int j = 0; j < b; j++)
            {
                for (int k = j; k < len; k += (b << 1))
                {
                    var t = z * a[k + b];
                    var u = a[k];
                    a[k] = u + t;
                    a[k + b] = u - t;
                }

                z *= inverse ? InvZ[i] : Z[i];
            }
        }
    }

    public static void Convolusion(ref ModInt[] a, ModInt[] b)
    {
        int sz = a.Length + b.Length - 1;
        int len = 1;
        int lg = 0;
        while (len < sz)
        {
            len <<= 1;
            lg++;
        }

        Array.Resize(ref a, len);
        Transform(a, lg, len, false);
        Array.Resize(ref b, len);
        Transform(b, lg, len, false);
        for (int i = 0; i < len; i++)
        {
            a[i] *= b[i];
        }

        Transform(a, lg, len, true);
        for (int i = 0; i < len; i++)
        {
            a[i] *= InvLen[lg];
        }

        Array.Resize(ref a, sz);
    }

    public static void Convolusion(ref ModInt[] a)
    {
        int sz = a.Length + a.Length - 1;
        int len = 1;
        int lg = 0;
        while (len < sz)
        {
            len <<= 1;
            lg++;
        }

        Array.Resize(ref a, len);
        Transform(a, lg, len, false);
        for (int i = 0; i < len; i++)
        {
            a[i] *= a[i];
        }

        Transform(a, lg, len, true);
        var inv = ModInt.Inverse(len);
        for (int i = 0; i < len; i++)
        {
            a[i] *= inv;
        }

        Array.Resize(ref a, sz);
    }

    private static int BitsReverse(int v, int lg)
    {
        if (v == 0) return v;
        int r = 0;
        if (lg % 2 == 1) r |= v & (1 << (lg / 2));
        for (int i = 0; i < lg / 2; i++)
        {
            r |= ((v >> i) & 1) << (lg - i - 1);
            r |= ((v >> (lg - i - 1)) & 1) << i;
        }

        return r;
    }
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    #region ModInt

    /// <summary>
    /// [0,<see cref="Mod"/>) までの値を取るような数
    /// </summary>
    public struct ModInt
    {
        /// <summary>
        /// 剰余を取る値．
        /// </summary>
        public const long Mod = 998244353;

        /// <summary>
        /// 実際の数値．
        /// </summary>
        public long num;

        /// <summary>
        /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
        /// </summary>
        /// <param name="n">インスタンスが持つ値</param>
        /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
        public ModInt(long n)
        {
            num = n;
        }

        /// <summary>
        /// このインスタンスの数値を文字列に変換します．
        /// </summary>
        /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
        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);
        }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(ModInt v, long k)
        {
            return Pow(v.num, k);
        }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1)
                    ret = ret * v % Mod;
            return new ModInt(ret);
        }

        /// <summary>
        /// 与えられた数の逆元を計算します．
        /// </summary>
        /// <param name="v">逆元を取る対象となる数</param>
        /// <returns>逆元となるような値</returns>
        /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
        public static ModInt Inverse(ModInt v)
        {
            return Pow(v, Mod - 2);
        }
    }

    #endregion

    #region Binomial Coefficient

    public class BinomialCoefficient
    {
        public ModInt[] fact, ifact;

        public BinomialCoefficient(int n)
        {
            fact = new ModInt[n + 1];
            ifact = new ModInt[n + 1];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i;
            ifact[n] = ModInt.Inverse(fact[n]);
            for (int i = n - 1; i >= 0; i--)
                ifact[i] = ifact[i + 1] * (i + 1);
            ifact[0] = ifact[1];
        }

        public ModInt this[int n, int r]
        {
            get
            {
                if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
                return fact[n] * ifact[n - r] * ifact[r];
            }
        }

        public ModInt RepeatedCombination(int n, int k)
        {
            if (k == 0) return 1;
            return this[n + k - 1, k];
        }
    }

    #endregion
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s = Console.ReadLine();
                while (s.Length == 0)
                {
                    s = Console.ReadLine();
                }

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            const long MOD = 998244353;

            var ntt = new NTT(MOD);

            int n = ReadInt();
            int k = ReadInt();
            int[] d = ReadIntArray();

            long[] result = { 1 };
            long[] a = new long[10];
            for (int i = 0; i < k; i++)
            {
                a[d[i]] = 1;
            }

            int n2 = n / 2;

            while (n2 > 0)
            {
                if ((n2 & 1) != 0)
                {
                    result = ntt.Multiply(result, a);
                }

                a = ntt.Multiply(a, a);
                n2 >>= 1;
            }

            long ans = 0;
            for (int i = 0; i < result.Length; i++)
            {
                ans = (ans + result[i] * result[i]) % MOD;
            }

            Writer.WriteLine(ans);
        }

        public class NTT
        {
            private readonly long MOD;

            private int maxBase;

            private long[] roots;

            private long[] invRoots;

            public NTT(long mod)
            {
                MOD = mod;

                long tmp = mod - 1;
                maxBase = 0;
                while (tmp % 2 == 0)
                {
                    maxBase++;
                    tmp /= 2;
                }

                long baseRoot = 2;
                while (true)
                {
                    if (Pow(baseRoot, 1 << maxBase) == 1)
                    {
                        if (Pow(baseRoot, 1 << (maxBase - 1)) != 1)
                        {
                            break;
                        }
                    }
                    baseRoot++;
                }

                roots = new long[maxBase];
                roots[0] = baseRoot;
                for (int i = 1; i < maxBase; i++)
                {
                    roots[i] = (roots[i - 1] * roots[i - 1]) % MOD;
                }
                invRoots = new long[maxBase];
                for (int i = 0; i < maxBase; i++)
                {
                    invRoots[i] = Pow(roots[i], mod - 2);
                }
            }

            public long[] Multiply(long[] a, long[] b)
            {
                int n = 1;
                int p = 0;
                while (n < Math.Max(a.Length, b.Length))
                {
                    n <<= 1;
                    p++;
                }
                n <<= 1;
                p++;

                if (p > maxBase)
                {
                    throw new InvalidOperationException($"Mod {MOD} cannot be used ({p} > {maxBase}).");
                }

                var fa = new long[n];
                Array.Copy(a, fa, a.Length);
                var fb = new long[n];
                Array.Copy(b, fb, b.Length);

                FFT(fa, p, false);
                FFT(fb, p, false);

                for (int i = 0; i < n; i++)
                {
                    fa[i] = fa[i] * fb[i] % MOD;
                }

                FFT(fa, p, true);
                long invN = Pow(n, MOD - 2);
                for (int i = 0; i < n; i++)
                {
                    fa[i] = fa[i] * invN % MOD;
                }
                return fa;
            }

            private void FFT(long[] a, int p, bool invert)
            {
                int n = a.Length;
                if (n == 1)
                {
                    return;
                }

                var a0 = new long[n / 2];
                var a1 = new long[n / 2];
                for (int i = 0; i < n / 2; i++)
                {
                    a0[i] = a[2 * i];
                    a1[i] = a[2 * i + 1];
                }
                FFT(a0, p - 1, invert);
                FFT(a1, p - 1, invert);

                long w = 1;
                long wn = invert ? invRoots[maxBase - p] : roots[maxBase - p];

                for (int i = 0; i < n / 2; i++)
                {
                    long d = w * a1[i] % MOD;
                    a[i] = a0[i] + d;
                    if (a[i] >= MOD)
                    {
                        a[i] -= MOD;
                    }
                    a[i + n / 2] = a0[i] - d;
                    if (a[i + n / 2] < 0)
                    {
                        a[i + n / 2] += MOD;
                    }
                    w = w * wn % MOD;
                }
            }

            private long Pow(long a, long n)
            {
                long result = 1;

                while (n > 0)
                {
                    if ((n & 1) > 0)
                    {
                        result = (result * a) % MOD;
                    }

                    a = (a * a) % MOD;
                    n >>= 1;
                }

                return result;
            }
        }

        public static void Solve()
        {
            // var sw = Stopwatch.StartNew();

            SolveCase();

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                // Writer.WriteLine("Case {0}:", i + 1);
                // Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

            // sw.Stop();
            // Console.WriteLine(sw.ElapsedMilliseconds);
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            // Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

        public static string ReadLine()
        {
            return Reader.ReadLine();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            const int MOD = 998244353;

            var ntt = new NTTFast(MOD);

            int n = ReadInt();
            int k = ReadInt();
            int[] d = ReadIntArray();

            int[] result = { 1 };
            int[] a = new int[10];
            for (int i = 0; i < k; i++)
            {
                a[d[i]] = 1;
            }

            int n2 = n / 2;

            while (n2 > 0)
            {
                if ((n2 & 1) != 0)
                {
                    result = ntt.Multiply(result, a);
                }

                a = ntt.Multiply(a, a);
                n2 >>= 1;
            }

            long ans = 0;
            for (int i = 0; i < result.Length; i++)
            {
                ans = (ans + (long) result[i] * result[i]) % MOD;
            }

            Writer.WriteLine(ans);
        }

        public class NTTFast
        {
            private int curBase = 1;
            private int[] roots = { 0, 1 };
            private int[] rev = { 0, 1 };
            private int maxBase = -1;
            private int root = -1;

            private readonly int MOD;

            public NTTFast(int mod)
            {
                MOD = mod;
            }

            private void Init()
            {
                int tmp = MOD - 1;
                maxBase = 0;
                while (tmp % 2 == 0)
                {
                    tmp /= 2;
                    maxBase++;
                }
                root = 2;
                while (true)
                {
                    if (Power(root, 1 << maxBase) == 1)
                    {
                        if (Power(root, 1 << (maxBase - 1)) != 1)
                        {
                            break;
                        }
                    }
                    root++;
                }
            }

            void ensure_base(int nBase)
            {
                if (maxBase == -1)
                {
                    Init();
                }
                if (nBase <= curBase)
                {
                    return;
                }
                if (nBase > maxBase)
                {
                    throw new InvalidOperationException();
                }
                Array.Resize(ref rev, 1 << nBase);
                for (int i = 0; i < (1 << nBase); i++)
                {
                    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nBase - 1));
                }
                Array.Resize(ref roots, 1 << nBase);
                while (curBase < nBase)
                {
                    int z = Power(root, 1 << (maxBase - 1 - curBase));
                    for (int i = 1 << (curBase - 1); i < (1 << curBase); i++)
                    {
                        roots[i << 1] = roots[i];
                        roots[(i << 1) + 1] = (int)((long)roots[i] * z % MOD);
                    }
                    curBase++;
                }
            }

            public void FFT(int[] a)
            {
                int n = a.Length;
                if ((n & (n - 1)) != 0)
                {
                    throw new InvalidOperationException();
                }
                int zeros = get__builtin_ctz(n);
                ensure_base(zeros);
                int shift = curBase - zeros;
                for (int i = 0; i < n; i++)
                {
                    if (i < (rev[i] >> shift))
                    {
                        int tmp = a[i];
                        a[i] = a[rev[i] >> shift];
                        a[rev[i] >> shift] = tmp;
                    }
                }
                for (int k = 1; k < n; k <<= 1)
                {
                    for (int i = 0; i < n; i += 2 * k)
                    {
                        for (int j = 0; j < k; j++)
                        {
                            int x = a[i + j];
                            int y = (int)((long)a[i + j + k] * roots[j + k] % MOD);
                            a[i + j] = x + y - MOD;
                            if (a[i + j] < 0)
                            {
                                a[i + j] += MOD;
                            }
                            a[i + j + k] = x - y + MOD;
                            if (a[i + j + k] >= MOD)
                            {
                                a[i + j + k] -= MOD;
                            }
                        }
                    }
                }
            }

            // todo: rename? remove?
            private int get__builtin_ctz(int n)
            {
                int c = 0;
                while (n > 0 && (n & 1) == 0)
                {
                    c++;
                    n >>= 1;
                }
                return c;
            }

            public int[] Multiply(int[] a, int[] b, int eq = 0)
            {
                int need = a.Length + b.Length - 1;
                int nbase = 0;
                while ((1 << nbase) < need)
                {
                    nbase++;
                }
                ensure_base(nbase);
                int sz = 1 << nbase;
                Array.Resize(ref a, sz);
                Array.Resize(ref b, sz);
                FFT(a);
                if (eq != 0)
                {
                    b = a;
                }
                else
                {
                    FFT(b);
                }
                int invSz = Inv(sz);
                for (int i = 0; i < sz; i++)
                {
                    a[i] = (int)((long)(int)((long)a[i] * b[i] % MOD) * invSz % MOD);
                }
                Array.Reverse(a, 1, a.Length - 1);
                FFT(a);

                int newSize = need;
                while (newSize > 0 && a[newSize - 1] == 0)
                {
                    newSize--;
                }
                Array.Resize(ref a, newSize);

                return a;
            }

            public int[] Square(int[] a)
            {
                return Multiply(a, a, 1);
            }

            private int Power(int a, long b)
            {
                int res = 1;
                while (b > 0)
                {
                    if ((b & 1) > 0)
                    {
                        res = (int)((long)res * a % MOD);
                    }
                    a = (int)((long)a * a % MOD);
                    b >>= 1;
                }
                return res;
            }

            private int Inv(int a)
            {
                a %= MOD;
                if (a < 0)
                {
                    a += MOD;
                }
                int b = MOD;
                int u = 0;
                int v = 1;
                while (a != 0)
                {
                    int t = b / a;
                    b -= t * a;

                    int tmp = a;
                    a = b;
                    b = tmp;

                    u -= t * v;

                    tmp = u;
                    u = v;
                    v = tmp;
                }
                if (u < 0)
                {
                    u += MOD;
                }
                return u;
            }
        }

        public static void Solve()
        {
#if DEBUG
            var sw = Stopwatch.StartNew();
#endif

            SolveCase();

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

#if DEBUG
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
#endif
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            //Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

        public static string ReadLine()
        {
            return Reader.ReadLine();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round88 {
    class B {
        static void Mai() {
            var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss => long.Parse(sss));
            long a = xs[0], b = xs[1], mod = xs[2];
            for (long i = 1; i < mod && i <= a; i++) {
                long v = 1000000000L * i % mod;
                if ((mod - v) % mod > b) {
                    Console.WriteLine("1 {0}", i.ToString().PadLeft(9, '0'));
                    return;
                }
            }
            Console.WriteLine(2);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round88 {
    class B {
        static void Main() {
            var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss => long.Parse(sss));
            long a = xs[0], b = xs[1], mod = xs[2];
            for (long i = 0; i <= a; i++) {
                long v = 1000000000L * i % mod;
                if ((mod - v) % mod > b) {
                    Console.WriteLine("1 {0}", i.ToString().PadLeft(9, '0'));
                    return;
                }
            }
            Console.WriteLine(2);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Collections;

namespace Task
{
    class MyIo
    {
        char[] separators = new char[] { ' ', '\t' };

#if TEST
        TextReader inputStream = new StreamReader("..\\..\\input.txt");
#else
        TextReader inputStream = System.Console.In;
#endif
        TextWriter outputStream = Console.Out;

        string[] tokens;
        int pointer;

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(format, args);
        }

        public void PrintLine(string format, params object[] args)
        {
            outputStream.WriteLine(format, args);
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }
    }

    class Program
    {
        MyIo io = new MyIo();

        void Solve()
        {
            // Place your code here

            int a = io.NextInt();
            int b = io.NextInt();
            int mod = io.NextInt();

            if (b >= mod)
            {
                io.Print(2);
                return;
            }

            BitArray bits = new BitArray(mod);
            int result = -1;
            for (int A = 1; A <= a; A++)
            {
                long mlp = A * 1000000000L;
                long temp = mlp % mod;
                if (temp != 0)
                {
                    if (mlp - temp > b)
                    {
                        result = A;
                        break;
                    }
                }
                if (bits[(int)mlp])
                    break;
                bits[(int)mlp] = true;
            }

            if (result == -1)
                io.Print(2);
            else
            {
                string s = result.ToString();
                while (s.Length < 9)
                    s = "0" + s;
                io.Print(1 + " " + s);
            }
        }

        static void Main(string[] args)
        {
            var p = new Program();

            p.Solve();
            p.io.Close();
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;

namespace contest
{
    class Program
    {
        static int[] arr = new int[150005];

        public static void Main()
        {
            int n , k;
            var inp = Console.ReadLine().Split(' ');
            n = int.Parse(inp[0]);
            k = int.Parse(inp[1]);
            inp = Console.ReadLine().Split(' ');
            for( int i = 0; i < n; i++ )
            {
                arr[i] = int.Parse(inp[i]);
            }
            int ans = int.MaxValue;
            for( int i = 0; i <= 100000; i++)
            {
                List<int> list = new List<int>();

                int cnt = 0;
                for( int j = 0; j < n; j++ )
                {
                    cnt = 0;
                    int x = arr[j];
                    while( x > i)
                    {
                        cnt++;
                        x /= 2;
                    }
                    if( x == i )
                    {
                        list.Add(cnt);
                    }
                }
                list.Sort();
                if( list.Count >= k )
                {
                    int sm = 0;
                    for (int j = 0; j < k; j++)
                        sm += list[j];
                    ans = Math.Min(ans, sm);
                }
            }
            Console.WriteLine(ans);
            Console.ReadLine();
        }

    }
}