import java.io.*;
import java.util.*;

public class Main {

	public static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			tokenizer = null;
		}

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			return arr;
		}

		public Integer[] nextIntegerArr(int n) {
			Integer[] arr = new Integer[n];
			for (int i = 0; i < n; i++) {
				arr[i] = new Integer(this.nextInt());
			}
			return arr;
		}

		public int[][] next2DIntArr(int n, int m) {
			int[][] arr = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					arr[i][j] = this.nextInt();
				}
			}
			return arr;
		}

		public int[] nextSortedIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			Arrays.sort(arr);
			return arr;
		}

		public long[] nextLongArr(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextLong();
			}
			return arr;
		}

		public long[] nextSortedLongArr(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			Arrays.sort(arr);
			return arr;
		}

		public char[] nextCharArr(int n) {
			char[] arr = new char[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextChar();
			}
			return arr;
		}
	}

	public static InputReader scn = new InputReader();
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		// InputStream inputStream = System.in; // Useful when taking input other than
		// console eg file handling // check ctor of inputReader
		// To print in file use this:- out = new PrintWriter("destination of file")
		// including extension");

		int n = scn.nextInt(), p = scn.nextInt(), k = 1;
		long ans = 0;
		while (k <= n) {
			String str = Long.toString(k);
			long num = Long.parseLong(str + rev(k));
			ans += num;
			k++;
		}

		System.out.println(ans % p);
	}

	public static String rev(long n) {
		StringBuilder s = new StringBuilder(Long.toString(n));
		return s.reverse().toString();
	}
}

import java.util.*;

public class R2 {
    public static void main(String... xxx)
    {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int p = sc.nextInt();
        long ans = 0;

        for (int i = 1; i <= k; i++) {
            ans += Long.valueOf(i + (new StringBuilder(Integer.toString(i))).reverse().toString()) % p;
        }

        System.out.print(ans%p);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author caoash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BChthollysRequest solver = new BChthollysRequest();
        solver.solve(1, in, out);
        out.close();
    }

    static class BChthollysRequest {
        public void solve(int testNumber, FastScanner br, PrintWriter pw) {
            int k = br.nextInt();
            long MOD = br.nextLong();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                StringBuilder curr = new StringBuilder(i + "");
                curr.reverse();
                String ans = (i + "") + curr;
                sum += Long.parseLong(ans);
                sum %= MOD;
            }
            pw.println(sum);
            pw.close();
        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastScanner.SpaceCharFilter filter;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);

		int k=scan.nextInt();
		int P=scan.nextInt();

		long sum=0;
		for(int i=1;i<=k;i++){
			String first=i+"";
			StringBuilder last=new StringBuilder(first).reverse();

			sum+=Long.parseLong(first+last);
			sum=sum%P;
		}

		System.out.println(sum);

	}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class HelloWorld {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);

		int k = in.nextInt();
		int p = in.nextInt();
		long sum = 0;
		int count = 0;
		int currentElement = 1;
		while(count < k) {
			String number = Integer.toString(currentElement);
			String newNumber = number + (new StringBuilder(number).reverse().toString());
			//System.out.println(number);
			sum = (sum + Long.parseLong(newNumber)) % p;
			currentElement++;
			count = count + 1;
		}
		System.out.println(sum);
	}
}

import java.util.*;
public class Code {
    public  static  void main(String... arg){
        Scanner sc = new Scanner(System.in);
        long n , k;
        n = sc.nextLong();
        k = sc.nextLong();
        long ans =0;
        for(long i=1; i<= n;i++) {
            String s = String.valueOf(i);
            String s1 = new StringBuffer(s).reverse().toString();
            s = s + s1;
            //System.out.println(s);
            long y = Long.parseLong(s);
            ans = (ans%k + y%k)%k;

        }
        System.out.println(ans);
    }
}

import java.util.*;
public class B {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long p = sc.nextInt();
		long ans=0;
		for(int i=1;i<=k;i++){
			String s1 = Integer.toString(i);
			String s2="";
			for(int j = s1.length() - 1; j >= 0; j--) {
				s2 = s2 + s1.charAt(j); }
			String ss = ""+s1+s2;
			long value = Long.parseLong(ss);
			ans = ((ans%p) + (value%p))%p;
		}
		System.out.println(ans);
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {

	public static long f(long k) {
		long ans=0;
		String t=k+"";
		String nt="";
		for(int i=0;i<t.length();i++) {
			nt=t.charAt(i)+nt;
		}
		//System.out.println(nt);
		ans=Long.parseLong(t+nt);
		return ans;
	}
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        InputReader in = new InputReader(inputStream);

        long k=in.nextLong(), p=in.nextLong();
        long ans=0;
        for(long i=1;i<=k;i++) {
        	ans+=f(i);
        	ans%=p;
        }
        out.println(ans);
        out.close();
    }

    static class InputReader {

        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream), 32624);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public long[] nextArrayl(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
        public double[] nextArrayd(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextDouble();
            }
            return a;
        }

        private BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public void printAr(int[] a) {
            System.out.print("[");
            for (long x : a) {
                System.out.print(x + ",");
            }
            System.out.print("]");
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static long f(long k) {
		long ans=0;
		String t=k+"";
		String nt="";
		for(int i=0;i<t.length();i++) {
			nt=t.charAt(i)+nt;
		}
		//System.out.println(nt);dfgdfgdfgdfgf
		ans=Long.parseLong(t+nt);
		return ans;
	}
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        InputReader in = new InputReader(inputStream);

        long k=in.nextLong(), p=in.nextLong();
        long ans=0;
        for(long i=1;i<=k;i++) {
        	ans+=f(i);
        	ans%=p;
        }
        out.println(ans);
        out.close();
    }

    static class InputReader {

        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream), 32624);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public long[] nextArrayl(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
        public double[] nextArrayd(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextDouble();
            }
            return a;
        }

        private BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public void printAr(int[] a) {
            System.out.print("[");
            for (long x : a) {
                System.out.print(x + ",");
            }
            System.out.print("]");
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static long f(long k) {
		long ans=0;
		String t=k+"";
		String nt="";
		for(int i=0;i<t.length();i++) {
			nt=t.charAt(i)+nt;
		}
		//System.out.println(nt);
		ans=Long.parseLong(t+nt);
		return ans;
	}
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        InputReader in = new InputReader(inputStream);

        long k=in.nextLong(), p=in.nextLong();
        long ans=0;
        for(long i=1;i<=k;i++) {
        	ans+=f(i);
        	ans%=p;
        }
        out.println(ans);
        out.close();
    }

    static class InputReader {

        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream), 32624);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public long[] nextArrayl(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
        public double[] nextArrayd(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextDouble();
            }
            return a;
        }

        private BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public void printAr(int[] a) {
            System.out.print("[");
            for (long x : a) {
                System.out.print(x + ",");
            }
            System.out.print("]");
        }
    }

}

import java.io.*;
import java.util.*;

public class B implements Runnable{
	public static void main (String[] args) {new Thread(null, new B(), "_cf", 1 << 28).start();}

	long res = 0;
	long p;
	int k;

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		System.err.println("Go!");

		k = fs.nextInt();
		p = fs.nextInt();
		res = 0;
		long sub = 9;
		long ssub = 495;
		int length = 2;
		while(k > 0) {
			if(k - sub < 0) {
				break;
			}
			else {
				//go
				res += ssub; res %= p;
				k -= sub; sub *= 10;
				ssub *= 1000; ssub %= p;
				length += 2;
			}
		}

        if(1 == 2) {
		    System.out.println(k + " " + sub + " " + length);
        }

		if(k > 0)
			go("", length);

		out.println(res);

		out.close();
	}

	void go (String str, int length) {
		if(length == 0) {
			res += Long.parseLong(str);
			res %= p;
			k--;
			return;
		}
		for(int dig = 0; dig <= 9 && k > 0; dig++) {
			if(str.length() == 0 && dig == 0) continue;
			if(str.length() == 0) {
				go(dig+""+dig, length-2);
			}
			else {
				go(str.substring(0, str.length()/2) + "" + dig + "" + dig + "" + str.substring(str.length()/2), length-2);
			}
		}
	}

	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 1000; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				//				br = new BufferedReader(new FileReader("cases.in"));
				st = new StringTokenizer("");
			} catch (Exception e){e.printStackTrace();}
		}
		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}
		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}
		public Integer[] nextIntegerArray(int n) {
			Integer[] a = new Integer[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public char[] nextCharArray() {return nextLine().toCharArray();}
	}

}

import java.io.BufferedInputStream;
import java.io.FileReader;
import java.util.Scanner;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {

	public static void main(String args[]) {
		Scanner cin = new Scanner(new BufferedInputStream(System.in));
		int k = cin.nextInt();
		int p = cin.nextInt();
		long suma = 0;
		for (int i = 1; i <= k; i++) {
			String sa = ("" + i);
			String sb = new StringBuffer(sa).reverse().toString();
			sa += sb;
			suma += Long.parseLong(sa);
			suma %= p;
		}

		System.out.println(suma);
	}
}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class CF443A {
	static MyScanner in = new MyScanner();
	static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

	static boolean isZcy(long n) {
		String s = String.valueOf(n);
		if (s.length() % 2 == 1) {
			return false;
		}
		String reverse = new StringBuilder(s).reverse().toString();
		return reverse.equals(s);
	}

	static long[] arr = new long[100001];

	public static void main(String[] args) {
		Arrays.fill(arr, Long.MAX_VALUE);
		long ans = 0;
		long k = in.nextInt(), p = in.nextInt();
		long i = 1;
		long K = k;
		k = 100_000;
		long currLen = 1;
		while (k > 0) {
			long len = String.valueOf(i).length();
			if (currLen < len) {
				currLen = len;
				i = 1;
			}
			String str = String.valueOf(i);
			int zeroesToAdd = (int) (currLen - str.length());
			// i %= Math.pow(10, currLen);
			if (i % 10 == 0) {
				i++;
				continue;
			}
			for (int j = 0; j < zeroesToAdd; j++) {
				str = "0" + str;
			}

			long t = Long.valueOf(new StringBuilder(str).reverse().toString() + str);
			// out.println(t);
			if (isZcy(t)) {
				k--;
				arr[(int) k] = t;

			}
			i++;
		}
		Arrays.sort(arr);
		for (int j = 0; j < K; j++) {
			ans += arr[j];
			ans %= p;
		}
		out.println(ans);
		// out.print(count > 0 ? "YES" : "NO");
		// long k = in.nextLong();
		// String s = in.next();
		// int[] arr = new int[n];
		// for (int i = 0; i < n; i++) {
		// arr[i] = in.nextInt();
		// }

		/*
		 * Dont delete
		 */
		out.close();
		/*
		 *
		 */
	}

	// BIN seach
	// while (l != r) {
	// mid = (l + r) / 2;
	// if (check(mid)) {
	// ans = mid;
	// l = mid + 1;
	// } else {
	// r = mid;
	// }
	// }
	public static long GCD(long a, long b) {
		return b == 0 ? a : GCD(b, a % b);
	}

	public static long LCM(long a, long b) {
		return a * b / GCD(a, b);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.OutputStream;
import java.io.PrintWriter;

public class ChthollysRequest {
    public static void main(String[] args) throws IOException{
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1,in,out);
        out.flush();
    }
    public static class TaskA{
        void solve(int t,InputReader in,PrintWriter out) throws IOException{
            long k = in.nextLong() , p = in.nextLong() , sum = 0;
            for (int i = 1;i <= k;i++){
                StringBuilder s1 = new StringBuilder(i+"");
//                String s2 =rev(s1);
                long v = Long.parseLong(s1.toString()+s1.reverse());
//                sum = add(sum,v,p);
                sum = (sum+v)%p;
            }
            out.println(sum);
        }
        String rev(String s){
//            String x = s.toString();
            char[] ans = s.toCharArray();
            int N = ans.length;
            for (int i = 0; i < N / 2; i++) {
                char tmp = ans[i];
                ans[i] = ans[N - i - 1];
                ans[N - i - 1] = tmp;
            }
//            String comp1 = new String(ans);
//            String comp2 = (s.reverse().toString());
//            if(comp1.equals(comp2))
//                System.out.println("yes");
//            else System.out.println("no");
//            return s.reverse();
            return new String(ans);
        }
        long add(long sum,long v,long p){
            return (sum+v)%p;
        }
    }
    public static class InputReader{
        public BufferedReader reader;
        public StringTokenizer tk;
        public InputReader(InputStream s){
            reader = new BufferedReader(new InputStreamReader(s));
        }
        public String next() throws IOException {
            while (tk == null || !tk.hasMoreTokens())
                tk = new StringTokenizer(reader.readLine());
            return tk.nextToken();
        }
        public int nextInt()throws IOException{ return Integer.parseInt(next()); }
        public long nextLong() throws IOException {return Long.parseLong(next());}
        public double nextDouble() throws IOException{return Double.parseDouble(next());}
        public String ReadLine() throws IOException{return reader.readLine();}
        public boolean ready() throws IOException{return reader.ready();}
    }
}

import java.util.*;
public class Test{
    public static void main(String[] afzal){
        Scanner sc = new Scanner(System.in);
        long K = sc.nextLong();
        long P = sc.nextLong();
        String str = Long.toString(K);
        String st = new StringBuffer(str).reverse().toString();
        str = str+st;
        long A = Long.parseLong(str);
        for(long i=K-1;i>=1;i--){
            str = Long.toString(i);
            st = new StringBuffer(str).reverse().toString();
            str = str+st;
            long r = Long.parseLong(str);
            A = A+r;
        }
        System.out.println(A%P);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ali
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long k = in.nextLong(), p = in.nextLong(), sum = 0;
            for (int i = 1; i <= k; i++) {
                StringBuilder s1 = new StringBuilder(i + "");
//                String s2 =rev(s1);
                long v = Long.parseLong(s1.toString() + s1.reverse());
//                sum = add(sum,v,p);
                sum = (sum + v) % p;
            }
            out.printLine(sum);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.ArrayList;
import java.util.Scanner;

public class ChthollysRequest {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int mod = sc.nextInt();
		long sum = 0;
		int cnt = 0;
		ArrayList<String> nums = new ArrayList<>();

		nums.add("");
		rec(N, nums, cnt);
		nums.remove(0);
		for (String s : nums) {
			if(s.charAt(0) == '0') continue;
			sum += Long.parseLong(s);
			sum %= mod;
		}
		System.out.println(sum);
	}

	public static void rec(int N, ArrayList<String> nums, int counter) {

		int nl = nums.get(nums.size() - 1).length();

		int s = nums.size();
		for (int out = 0; out < 10 && counter < N; out++) {
			for (int i = 0; i < s && counter < N; i++) {
				String mid = nums.get(i);
				if(nl > mid.length()) continue;
				String str = out + "" + mid + "" + out;
				nums.add(str);
				if (out != 0)
					counter++;
			}
		}
		if (counter < N)
			rec(N, nums, counter);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author khokharnikunj8
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B879 solver = new B879();
        solver.solve(1, in, out);
        out.close();
    }

    static class B879 {
        private long ans = 0;

        private void pre(long p, int limit) {
            long current = 1l;
            for (int n = 1; n <= limit; n++) {
                String s = String.valueOf(n);
                String s1 = new StringBuffer(s).reverse().toString();
                s = s.concat(s1);
                ans = (ans + (Long.parseLong(s))) % p;
            }
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            long p = in.scanLong();
            pre(p, n);
            out.println(ans % p);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

    }
}

import javax.annotation.processing.SupportedSourceVersion;
import java.util.*;
import java.io.*;

public final class Main {

    public static void main(String[] args) throws Exception {
        PrintWriter pw = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine());
        int k = Integer.parseInt(st.nextToken());
        int p = Integer.parseInt(st.nextToken());

        long kSmallestSum = 0;

        for(int i = 1; i<=k; i++){

            //i + rev of i
            StringBuilder builder = new StringBuilder(i+"");
            builder.append(new StringBuilder(i+"").reverse());
            kSmallestSum += Long.parseLong(builder.toString());
            kSmallestSum %= p;
        }

        pw.print(kSmallestSum);
        pw.close();
    }
}

/*
import java.io.*;
public class Codeforces_449_2
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String temp1=br.readLine();
		String[] temp2=temp1.split(" ");
		long k=Long.parseLong(temp2[0]);
		long p=Long.parseLong(temp2[1]);
		long count=0;
		long num=11;
		long sum=0;
		while(count!=k)
		{
			if(palindrome(num)==1&&nod(num)%2==0)
			{
				sum+=num;
				count++;
			}
			num++;
			if(num==100||num==10000||num==1000000)
			{
				num=(num*10)+1;
			}
		}
		long ans=sum%p;
		System.out.println(ans);
	}
	public static long nod(long number)
	{
		long ans=1;
		if(number<10)
		{
			ans=1;
		}
		else if(number>10&&number<100)
		{
			ans=2;
		}
		else if(number>100&&number<1000)
		{
			ans =3;
		}
		else if(number>1000&&number<10000)
		{
			ans =4;
		}
		else if(number>10000&&number<100000)
		{
			ans =5;
		}
		else if(number>100000&&number<1000000)
		{
			ans =6;
		}
		return ans;
	}
	public static long palindrome(long number)
	{
		long palindrome=number;
		long reverse=0;
		while(palindrome!=0)
		{
			long remainder=palindrome%10;
			reverse=reverse*10+remainder;
			palindrome=palindrome/10;
		}
		if(number==reverse)
		{
			return 1;
		}
		return 0;
	}
}
 */
import java.io.*;
public class Codeforces_449_2
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String temp1=br.readLine();
		String[] temp2=temp1.split(" ");
		int k=Integer.parseInt(temp2[0]);
		long p=Long.parseLong(temp2[1]);
		long count=0;
		long num=1;
		long sum=0;
		while(count!=k)
		{
			long adnum=reverseandadd(num);
			{
				sum+=adnum;
				count++;
			}
			num++;
		}
		long ans=sum%p;
		System.out.println(ans);
	}
	public static long reverseandadd(long number)
	{
		String str=Long.toString(number);
		StringBuffer rev=new StringBuffer(str).reverse();
		String fin=str+rev;
		long ret=Long.parseLong(fin);
		return ret;
	}
}

import java.util.*;
import java.io.*;
import java.math.*;

    public  class Sample implements Runnable
    {

          static int max=1000005;
          static long[] a=new long[max];
          public static void solve()
          {
            int m=i(); int k=i();
            long sum=0;
            for(int i=1;i<=m;i++)
            {
              StringBuilder sb=new StringBuilder(""+i);
              long ans=Long.parseLong(""+i+(""+sb.reverse()));
              sum=(sum+(ans%k))%k;

            }
            out.println(sum);

          }
          public static int upperbound(int[] a,int low,int high,int key)
          {

            while(low<high)
            {
              int mid=(low+high)>>1;
              if(a[mid]>key)
              {
                high=mid;
              }
              else
              {
                low=mid+1;
              }
            }
            return low;
          }
          public static int lowerbound(int[] a,int low,int high,int key)
          {
            while(low<high)
            {
              int mid=(low+high)>>1;
              if(a[mid]>=key)
              {
                high=mid;
              }
              else
              {
                low=mid+1;
              }
            }
            return low;
          }

static int findMin(int arr[], int n)
{

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += arr[i];

    boolean[][] dp=new boolean[n+1][sum+1];

    for (int i = 0; i <= n; i++)
        dp[i][0] = true;

    for (int i = 1; i <= sum; i++)
        dp[0][i] = false;

    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=sum; j++)
        {

            dp[i][j] = dp[i-1][j];

            if (arr[i-1] <= j)
                dp[i][j] |= dp[i-1][j-arr[i-1]];
        }
    }

    int diff = Integer.MAX_VALUE;

    for (int j=sum/2; j>=0; j--)
    {
        if (dp[n][j] == true)
        {
            diff = sum-2*j;
            break;
        }
    }
    return diff;
}

          public void run()
          {
              solve();
              out.close();
          }

          public static void main(String[] args) throws IOException
          {
                new Thread(null, new Sample(), "whatever", 1<<26).start();
          }
         static class Pair implements Comparable<Pair>
         {
            long a;
            int b;

            Pair(){}
            Pair(long a,int b)
            {
                       this.a=a;
                       this.b=b;
            }

            public int compareTo(Pair x)
           {
                return Long.compare(x.a,this.a);
           }
        }

    ////////////////////////////////////////////////////// Merge Sort ////////////////////////////////////////////////////////////////////////

   static class Merge
   {

        public static void sort(long inputArr[])
        {
            int length = inputArr.length;
            doMergeSort(inputArr,0, length - 1);
        }

        private static void doMergeSort(long[] arr,int lowerIndex, int higherIndex)
        {
            if (lowerIndex < higherIndex) {
                int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
                doMergeSort(arr,lowerIndex, middle);
                doMergeSort(arr,middle + 1, higherIndex);
                mergeParts(arr,lowerIndex, middle, higherIndex);
            }
        }

        private static void mergeParts(long[]array,int lowerIndex, int middle, int higherIndex)
        {
            long[] temp=new long[higherIndex-lowerIndex+1];
            for (int i = lowerIndex; i <= higherIndex; i++)
            {
                temp[i-lowerIndex] = array[i];
            }
            int i = lowerIndex;
            int j = middle + 1;
            int k = lowerIndex;
            while (i <= middle && j <= higherIndex)
            {
                if (temp[i-lowerIndex] < temp[j-lowerIndex])
                {
                    array[k] = temp[i-lowerIndex];
                    i++;
                } else {
                    array[k] = temp[j-lowerIndex];
                    j++;
                }
                k++;
            }
            while (i <= middle)
            {
                array[k] = temp[i-lowerIndex];
                k++;
                i++;
            }
            while(j<=higherIndex)
            {
                array[k]=temp[j-lowerIndex];
                k++;
                j++;
            }
        }

    }

    /////////////////////////////////////////////////////////// Methods ////////////////////////////////////////////////////////////////////////

     static boolean isPal(String s)
     {
        for(int i=0, j=s.length()-1;i<=j;i++,j--)
        {
                if(s.charAt(i)!=s.charAt(j)) return false;
        }
        return true;
     }
     static String rev(String s)
     {
                StringBuilder sb=new StringBuilder(s);
                sb.reverse();
                return sb.toString();
     }
     static int gcd(int a,int b){return (a==0)?b:gcd(b%a,a);}
     static long gcdExtended(long a,long b,long[] x)
     {

        if(a==0){
            x[0]=0;
            x[1]=1;
            return b;
        }
        long[] y=new long[2];
        long gcd=gcdExtended(b%a, a, y);

        x[0]=y[1]-(b/a)*y[0];
        x[1]=y[0];

        return gcd;
    }

     boolean findSum(int set[], int n, long sum)
    {
      if (sum == 0)
         return true;
      if (n == 0 && sum != 0)
         return false;
      if (set[n-1] > sum)
         return findSum(set, n-1, sum);
      return findSum(set, n-1, sum) ||findSum(set, n-1, sum-set[n-1]);
    }

      public static long modPow(long base, long exp, long mod)
     {
        base = base % mod;
        long result = 1;
        while (exp > 0)
       {
            if (exp % 2 == 1)
            {
                result = (result * base) % mod;
            }
            base = (base * base) % mod;
            exp = exp >> 1;
       }
        return result;
    }

    static long[] fac;
    static long[] inv;
    static long mod=(long)1e9+7;
    public static void cal()
    {
        fac = new long[1000005];
        inv = new long[1000005];
        fac[0] = 1;
        inv[0] = 1;
        for (int i = 1; i <= 1000000; i++)
        {
            fac[i] = (fac[i - 1] * i) % mod;
            inv[i] = (inv[i - 1] * modPow(i, mod - 2, mod)) % mod;
        }
    }

    public static long ncr(int n, int r)
    {
        return (((fac[n] * inv[r]) % mod) * inv[n - r]) % mod;
    }

////////////////////////////////////////// Input Reader ////////////////////////////////////////////////////////////////////////////////////////////////////

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out= new PrintWriter(System.out);

    static class InputReader {

          private final InputStream stream;
          private final byte[] buf = new byte[8192];
          private int curChar, snumChars;
          private SpaceCharFilter filter;

          public InputReader(InputStream stream) {
                  this.stream = stream;
          }

          public int snext()
         {
                  if (snumChars == -1)
                          throw new InputMismatchException();
                  if (curChar >= snumChars) {
                          curChar = 0;
                          try {
                                  snumChars = stream.read(buf);
                          } catch (IOException e) {
                                  throw new InputMismatchException();
                          }
                          if (snumChars <= 0)
                                  return -1;
                  }
                  return buf[curChar++];
          }

          public int nextInt()
         {
                  int c = snext();
                  while (isSpaceChar(c))
                  {
                          c = snext();
                  }
                  int sgn = 1;
                  if (c == '-')
                  {
                          sgn = -1;
                          c = snext();
                  }
                  int res = 0;
                  do {
                          if (c < '0' || c > '9')
                                  throw new InputMismatchException();
                          res *= 10;
                          res += c - '0';
                          c = snext();
                  } while (!isSpaceChar(c));
                  return res * sgn;
          }

          public long nextLong()
          {
                  int c = snext();
                  while (isSpaceChar(c))
                  {
                          c = snext();
                  }
                  int sgn = 1;
                  if (c == '-')
                  {
                          sgn = -1;
                          c = snext();
                  }
                  long res = 0;
                  do {
                          if (c < '0' || c > '9')
                                  throw new InputMismatchException();
                          res *= 10;
                          res += c - '0';
                          c = snext();
                  } while (!isSpaceChar(c));
                  return res * sgn;
          }

          public int[] nextIntArray(int n)
          {
                  int a[] = new int[n];
                  for (int i = 0; i < n; i++)
                  {
                          a[i] = nextInt();
                  }
                  return a;
          }

          public long[] nextLongArray(int n)
          {
                  long a[] = new long[n];
                  for (int i = 0; i < n; i++)
                  {
                          a[i] = nextLong();
                  }
                  return a;
          }

          public String nextLine()
         {
                  int c = snext();
                  while (isSpaceChar(c))
                          c = snext();
                  StringBuilder res = new StringBuilder();
                  do {
                          res.appendCodePoint(c);
                          c = snext();
                  } while (!isEndOfLine(c));
                  return res.toString();
          }

          public boolean isSpaceChar(int c)
          {
                  if (filter != null)
                          return filter.isSpaceChar(c);
                  return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }

          private boolean isEndOfLine(int c)
          {
                  return c == '\n' || c == '\r' || c == -1;
          }

          public interface SpaceCharFilter
          {
                  public boolean isSpaceChar(int ch);
          }

    }

    static int i()
    {
        return sc.nextInt();
    }
    static long l(){
        return sc.nextLong();
    }
    static int[] iarr(int n)
    {
        return sc.nextIntArray(n);
    }
    static long[] larr(int n)
    {
        return sc.nextLongArray(n);
    }
    static String s(){
        return sc.nextLine();
    }

 }

/**
 * @author: Mehul Raheja
 */

import java.util.*;
import java.io.*;

public class ChthollyReq{

    /*
        Runtime = O()
     */
    static int N, M, K;
    static String s;
    static StringTokenizer st;
    static int[] d;

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(br.readLine());
        long N = Long.parseLong(st.nextToken());
        long M = Long.parseLong(st.nextToken());
        long sum = 0;
        for (int i = 1; i <= N; i++) {
            sum = ((sum + Long.parseLong(i +  (new StringBuffer(i+"")).reverse().toString()))%M);
        }
        System.out.println(sum);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javafx.scene.shape.Arc;

/**
 *
 * @author antonio
 */
public class CF_449_B_ChthollysRequest {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        StringTokenizer tok = new StringTokenizer(s);
        int k = Integer.parseInt(tok.nextToken());
        int p = Integer.parseInt(tok.nextToken());
        int cont = 0;
        int i = 0;
        long sum = 0;
        ArrayList<String> nums = new ArrayList<String>(110002);
        nums.add("");
        ArrayList<String> numsN = new ArrayList<String>(110002);
        ArrayList<String> numsT = new ArrayList<String>(110002);
        while(cont < 100000){
            ini: for (int l = 0; l < 10; l++) {
                for (String sn : nums) {
                    numsN.add(l + sn + l);
                    if(l != 0){
                        cont++;
                    }
                    if(cont == 100000){
                        break ini;
                    }
                }
            }
            nums = (ArrayList<String>) numsN.clone();
            numsT.addAll(numsN);
            numsN = new ArrayList<>(110002);
        }
        while(k > 0){
            if(numsT.get(i).charAt(0) != '0'){
                sum += Long.parseLong(numsT.get(i));
                sum %= p;
                k--;
            }
            i++;
        }
        System.out.println(sum);
    }
}

import java.util.Scanner;

public class TaskB {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long p = sc.nextLong();

		long sum = 0;
		for(int i = 1; i <= k; i++) {
			sum += getNum(i);
			sum %= p;
		}
		System.out.println(sum%p);
	}

    public static long getNum(int value) {
	    long resultNumber = 0;
	    long cValue = value;
	    for(int i = value; i !=0; i /= 10) {
	        resultNumber = resultNumber * 10 + i % 10;
	        cValue *= 10;
	    }
	    return resultNumber+cValue;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class CFB {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;

    void solve() throws IOException {
        int k = nextInt();
        int p = nextInt();
        long res = 0;
        PriorityQueue<Long> pq = new PriorityQueue<>();
        for (int i = 1; i < 10; i++) {
            pq.add((long) 10 * i + i);
        }

        for (int i = 0; i < k; i++) {
            long nxt = pq.poll();
            res += nxt;
            if (res > p) {
                res -= p;
            }

            String all = Long.toString(nxt);
            String first = all.substring(0, all.length() / 2);
            StringBuilder sb = new StringBuilder(first);
            for (int j = 0; j < 10; j++) {
                StringBuilder tmp = new StringBuilder(sb);
                tmp.append(j);
                tmp.append(j);
                tmp.append(new StringBuilder(sb).reverse());
                long fur = Long.parseLong(tmp.toString());
                if (fur < (MOD << 10)) {
                    pq.add(fur);
                }
            }
        }

        out(res %  p);
    }

    boolean isSym(String str) {
        for (int i = 0, j = str.length() - 1; i < j; i++, j--) {
            if (str.charAt(i) != str.charAt(j)) {
                return false;
            }
        }

        return true;
    }
    void shuffle(long[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            long tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFB() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFB();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

import java.io.*;
import java.util.StringTokenizer;

public class B {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static long[] numbs = new long[100002];
    static long sum = 0;

    private static void calc(int k, PrintWriter out) {
        int counter = 0;
        for (int j = 1; j < 10; j++) {
            numbs[counter++] = j + j * 10;
        }

        long base = 10;
        while(counter < k) {
            base = base * 100;

            int d = (int)Math.ceil(Math.log10(base + 0.5d));

            int cur = counter;
            for (int h = 0; h < 9; h++) {
                long nextBase = base + h * (long)Math.pow(10f, d - 1)  + (h + 1);
                numbs[counter++] = nextBase;
                for (int j = 0; j < cur; j++) {
                    int curD = (int)Math.ceil(Math.log10(numbs[j] + 0.5d));
                    int power = d - curD;
                    numbs[counter++] = nextBase + numbs[j] * (long)Math.pow(10f, power / 2);
                    if (counter >= k) {
                        return;
                    }
                }
            }
        }
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int p = in.nextInt();

            calc(k, out);

            for (int j = 0; j < k; j++) {
                //out.println(numbs[j]);
                sum += numbs[j];
                sum %= p;
            }

            out.println(sum);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ahmed Ayman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static ArrayList<Long> a = new ArrayList<>();
        static int mod;

        static void generate(int size, StringBuilder sb, boolean start) {
            if (size == 0) {
                StringBuilder tmp = new StringBuilder(sb);
                tmp.append(sb.reverse());
                a.add(Long.parseLong(tmp.toString()));
                return;
            }
            if (start) {
                for (int i = 1; i <= 9; i++) {
                    StringBuilder tmp = new StringBuilder();
                    tmp.append(sb.toString());
                    tmp.append(i + "");
                    generate(size - 2, tmp, false);
                }
            } else {
                for (int i = 0; i <= 9; i++) {
                    StringBuilder tmp = new StringBuilder();
                    tmp.append(sb.toString());
                    tmp.append(i + "");
                    generate(size - 2, tmp, false);
                }
            }
        }

        static void generate() {
            int size = 2;
            while (a.size() <= 100001) {
                generate(size, new StringBuilder(), true);
                size += 2;
            }
            return;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int k = in.nextInt();
            mod = in.nextInt();
            long sum = 0;
            generate();
            for (int i = 0; i < k; i++) {
                sum = (sum + a.get(i)) % mod;
            }
            out.println(sum);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

// Problem: B. Chtholly's request
// Contest: Codeforces - Codeforces Round #449 (Div. 2)
// URL: https://codeforces.com/contest/897/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;

public class Main {
    private static PrintWriter pw = new PrintWriter(System.out);
    private static InputReader sc = new InputReader();

    static class InputReader{
        private static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer tk;

        private void next()throws IOException{
            while(tk == null || !tk.hasMoreTokens())
                tk = new StringTokenizer(r.readLine());
        }

        private int nextInt()throws IOException{
            next();
            return Integer.parseInt(tk.nextToken());
        }

        private long nextLong()throws IOException{
            next();
            return Long.parseLong(tk.nextToken());
        }
    }

    public static void main(String args[])throws IOException{
        int t = 1;
        while(t-->0)    solve();
        pw.flush();
        pw.close();
    }

    private static long mul(long a, long b, long p){
    	return (a%p * b%p)%p;
    }

    private static long add(long a, long b, long p){
    	return (a%p + b%p)%p;
    }

    private static long rev(long n){
    	long rev = 0;

    	while(n != 0){
    		rev = rev * 10 + n%10;
    		n /= 10;
    	}

    	return rev;
    }

    private static void solve()throws IOException{
		long k = sc.nextLong(), p = sc.nextInt(), no = 0, aux[] = {1, 10, 100, 1000, 10000, 100000, 1000000};
		int len = 0;
		long ans = 0;

		while(k -- >0){
			no++;
			long rev = rev(no);

			if(len < aux.length && aux[len] == no)
				len++;

			ans = add(ans, no*aux[len], p);
			ans = add(ans, rev, p);
		}

		pw.println(ans);
    }
}

import java.util.*;
public class A{
    public static void main(String arg[]){
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong(), p = sc.nextLong();
        int n = 11;
        long sum = 0;
        for(long i=1;k>0;i++){
            String s = Long.toString(i) + reverse(i);
            long v = Long.parseLong(s);
            sum = (sum + v)%p;
            k--;
        }
        System.out.println(sum);
    }
    static String reverse(long n){
        String str = Long.toString(n);
        String str2 = "";
        for(int i=0;i<str.length();i++) str2 = str.charAt(i) + str2;
        return str2;
    }

    static int isZCY(int n){
        String s = Integer.toString(n);
        int l = s.length();
        if(l%2==1) return l;
        for(int i=0;i<l/2;i++) if(s.charAt(i)!=s.charAt(l-1-i)) return 0;
        return -1;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st = new StringTokenizer("");

    public static void main(String[] args) {
        int k = ni();
        int p = ni();
        long sum = 0;
        for (int i = 1; i <= k; i++) {
            String s = Long.toString(i);
            sum = (sum + Long.parseLong(s + new StringBuilder(s).reverse())) % p;
        }
        System.out.println(sum);
    }

    private static String ns() {
        while (!st.hasMoreTokens()) try {
            st = new StringTokenizer(br.readLine());
        } catch (IOException ignored) {
        }
        return st.nextToken();
    }

    private static int ni() {
        return Integer.parseInt(ns());
    }

    private static long nl() {
        return Long.parseLong(ns());
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Liavontsi Brechka
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static
    @SuppressWarnings("Duplicates")
    class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            long p = in.nextInt();

            long res = 0;
            long f, s;
            for (int i = 1; i <= k; i++) {
                f = i;
                s = i;
                while (s > 0) {
                    f = f * 10 + s % 10;
                    s /= 10;
                }
                res += f;
                res %= p;
            }

            out.print(res);
        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(readLine());
            }
            return tokenizer.nextToken();
        }

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}

import java.util.Scanner;

public class App {

	public static long rev(int n, long p) {
		long num = n;
		long tmp = n;
		int ct = 0;
		long rev = 0;
		while (num != 0) {
			rev = rev * 10 + (num % 10);
			ct++;
			num = num / 10;
		}
		num = rev + tmp * (int) Math.pow(10, ct);
		return num % p;
	}

	public static void main(String[] args) {
		Scanner inp = new Scanner(System.in);
		int k = inp.nextInt();
		long p = inp.nextLong();
		long res = 0;
		for (int i = 0; i < k; i++) {
			res = (res + rev(i + 1, p)) % p;
		}
		System.out.println(res);
		inp.close();
	}

}

import java.util.*;
/**
 *
 * @author jeff
 */
public class JavaApplication1 {

    static long smallestPalindrome(String str){
        String rString = "";

        for(int i = str.length()-1;i>=0;i--){
            rString += str.charAt(i);
        }

        return Long.parseLong(str+""+rString);
    }

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        long k = in.nextLong();
        long p = in.nextLong();

        long sum = 0;
        int val = 0;
        String toPalindrome = "";

        for(int i = 0;i<k;i++) {
            val++;
            toPalindrome = String.valueOf(val);

            sum += smallestPalindrome(toPalindrome);
        }

        sum = sum % p;

        System.out.print(sum);

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.KeyStore.Entry;
import java.time.temporal.JulianFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.JLabel;

public class answertillD {
	static int minn;

	static class pair implements Comparable<pair> {
		int u;
		int v;

		public pair(int uo, int vo) {
			u = uo;
			v = vo;

		}

		@Override
		public String toString() {
			return "pair [u=" + u + ", v=" + v + "]";
		}

		@Override
		public int compareTo(pair e) {
			if (u == e.u && v == e.v)
				return 0;
			if (u > e.u || e.u > u)
				return u - e.u;
			else
				return 1;
		}
	}

	static class edge implements Comparable<edge> {
		int u;
		int v;
		int w;

		@Override
		public String toString() {
			return "edge [u=" + u + ", v=" + v + ", w=" + w + "]";
		}

		public edge(int uo, int vo, int wo) {
			u = uo;
			v = vo;
			w = wo;
		}

		@Override
		public int compareTo(edge e) {
			// TODO Auto-generated method stub
			return w - e.w;
		}
	}

	public static long power(long x, long y) {
		long ans = 1;
		while (y-- > 0) {
			if (ans <= 1e18 / x)
				ans *= x;
			else {
				ans = Long.MAX_VALUE;
				break;
			}
		}
		return ans;
	}

	public static char[][] reb() {
		int n = smallArr.length;
		char[][] arr = new char[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				arr[i][j] = smallArr[n - j - 1][i];

		return arr;
	}

	static int[] Arr, cost, level;
	static char[][] smallArr;
	static boolean[][] memo;
	static int n;
	static long S;
	static final int VISITED = 2, EXPLORED = 1, UNVISITED = 0;
	static ArrayList<Integer>[] adjList;
	static boolean[] visited, adjMat[];
	static int V, E;

	static long bfs(String str, int k) {
		Queue<String> q = new LinkedList<String>();
		q.add(str);
		HashSet<String> hs = new HashSet<String>();
		hs.add(str);
		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		hm.put(str, 0);
		long ans = 0;
		while (k > 0 && !q.isEmpty()) {
			String u = q.remove();
			for (int v = 0; v < u.length(); v++) {
				String sam = u.substring(0, v) + u.substring(v + 1);
				if (!hm.containsKey(sam)) {
					int x = hm.get(u) + 1;
					hm.put(sam, x);
					k--;
					ans += x;
					if (k == 0)
						break;
					q.add(sam);
				}
			}

		}
		if (k != 0)
			return -1;
		return ans;

	}

	public static long GCD(long a, long b) {
		if (b == 0)
			return a;
		return GCD(b, a % b);
	}

	public static long powerlog(long x, long y, int mod) {
		long res = 1; // Initialize result
		while (y > 0) {
			if ((y & 1) == 1)
				res = (res * x);
			// res %= mod;
			y = y >> 1; // y = y/2
			x = (x * x);
			// x %= mod;
		}
		return res;
	}

	public static String rev(String str) {
		StringBuilder sb = new StringBuilder();
		for (int i = str.length() - 1; i >= 0; i--) {
			sb.append(str.charAt(i));
		}
		return sb + "";
	}

	public static boolean checj(int numa, int b, int a, int n, int k) {
		int numb = n - numa;
		if (k % a == 0) {
			if (k / a - 1 < numa)
				return false;
		} else {
			if (k / a < numa)
				return false;
		}
		k -= numa * a;
		if (k % b == 0) {
			if (k / b - 1 < numb)
				return false;
		} else {
			if (k / b < numb)
				return false;
		}
		return true;
	}

	static int mod;
	static String ans;
	static int[] arr;

	public static boolean dp(int idx, int rem) {
		if (idx == n)
			return rem % mod == 0;

		if (!memo[idx][rem])
			return memo[idx][rem];
		if (cost[idx] != -1) {
			arr[idx] = cost[idx];
			return memo[idx][rem] = dp(idx + 1, (int) ((rem + cost[idx] * powerlog(10, n - 1 - idx, mod)) % mod));

		}
		boolean flag = false;
		for (int i = 0; i < 10; i++) {
			if (idx == 0 && i == 0)
				continue;
			arr[idx] = i;
			flag = dp(idx + 1, (int) ((rem + i * powerlog(10, n - idx - 1, mod)) % mod));
			if (flag)
				break;
		}

		return memo[idx][rem] = flag;
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int p = sc.nextInt();
		long ans = 0;
		long sum = 0;
		int shift1 = 0;
		int shift2 = 0;
		int shift3 = 0;
		int shift4 = 0;
		int shift5 = 0;
		outer: for (int i = 0; i < 10; i++) {
			if (i == 1)
				shift1++;
			long r = powerlog(10, 0, p) * i + powerlog(10, 11, p) * i;
			sum += r;
			// sum%=p;
			for (int j = 0; j < 10; j++) {
				if (j == 1&&i==0)
					shift2++;
				int sumssss = shift1;
				long q = powerlog(10, 0 + sumssss, p) * j + powerlog(10, 9 + sumssss, p) * j;
				sum += q;
				// sum%=p;
				for (int k = 0; k < 10; k++) {
					if (k == 1&&j==0&&i==0)
						shift3++;
					int sumsss = shift1 + shift2;
					long o = powerlog(10, 0 + sumsss, p) * k + powerlog(10, 7 + sumsss, p) * k;
					sum += o;
					// sum%=p;
					for (int l = 0; l < 10; l++) {
						if (l == 1&&k==0&&j==0&&i==0)
							shift4++;
						int sumss = shift1 + shift2 + shift3;
						long z = powerlog(10, 0 + sumss, p) * l + powerlog(10, 5 + sumss, p) * l;
						sum += z;
						// sum%=p;
						for (int m = 0; m < 10; m++) {
							if (m == 1&&l==0&&k==0&&j==0&&i==0)
								shift5++;
							int sums = shift1 + shift2 + shift3 + shift4;
							long y = powerlog(10,  sums, p) * m + powerlog(10, 3 + sums, p) * m;
							sum += y;
							// sum%=p;
							for (int u = 0; u < 10; u++) {
								int sumsh = shift1 + shift2 + shift3 + shift4 + shift5;
								long x = powerlog(10, sumsh, p) * u + powerlog(10, 1 + sumsh, p) * u;
								sum += x;
							//	System.out.println(sumsh+" "+sum);

								ans += (sum % p);
								sum -= x;
								ans %= p;
								if (sumsh == 0 && u == 0)
									continue;
								n--;
								if (n == 0)
									break outer;

							}
							sum -= y;
						}
						sum -= z;
					}
					sum -= o;
				}
				sum -= q;
			}
			sum -= r;
		}
		pw.print(ans);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}

import java.util.*;

public class Shashank
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        long k = scan.nextLong();
        long p = scan.nextLong();

        long sum = 0;
        for(int i = 1; i <= k; i++)
        {
            StringBuilder input = new StringBuilder();
            input.append(Long.toString(i));
            input = input.reverse();
            sum = (sum + Long.parseLong(Long.toString(i) + input)) % p;
        }
        System.out.println(sum);
    }
}

import java.util.*;
import java.io.*;
public class codeforces{
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			String s = null;
			try {
				s = reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return s;
		}

		public String nextParagraph() {
			String line = null;
			String ans = "";
			try {
				while ((line = reader.readLine()) != null) {
					ans += line;
				}
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return ans;
		}
	}
	//static int mod = 1000000007;
	static void printArray(int ar[]){
		for(int x:ar)
			System.out.print(x+" ");
	}
	static void printMatrix(int ar[][],int n){
		for(int i=0;i<n;i++){
			for(int j=i;j<n;j++){
				System.out.print(ar[i][j]+" ");
			}
			System.out.println();
		}
	}
	static class Data{
		int t;
		int l;
		int r;
		public Data(int t,int l,int r){
			this.t=t;
			this.l=l;
			this.r=r;
		}
	}
	static int gcd(int a, int b){
	    if (a == 0)
	        return b;
	    return gcd(b%a, a);
	}
	public static void main(String args[]){
		InputReader sc=new InputReader();
		PrintWriter pw=new PrintWriter(System.out);
		LinkedList<Long> queue = new LinkedList<Long>();
		int k=sc.nextInt();
		int p=sc.nextInt();
		int i=0;
		long total = 0;
		for(i=1;i<=9;i++){
			long val = i*(int)Math.pow(10,1)+i;
			queue.addLast(val);
		}
		boolean isOkay = false;
		for(i=1;i<=k;i++){
			if(queue.size() > k){
				isOkay = true;
			}
			if(isOkay){
				total = ((total%p)+(queue.pollFirst()%p))%p;
			}else{
				long val = queue.pollFirst();
				total = ((total%p)+(val%p))%p;
				String str = Long.toString(val);
				int ten = (str.length()/2);
				String fh = str.substring(0,ten);
				String lh = str.substring(ten);
				for(int j=0;j<=9;j++){
					String mid = ""+Integer.toString(j);
					mid+=Integer.toString(j);
					String result = fh+mid+lh;
					long r = Long.parseLong(result);
					queue.addLast(r);
					if(queue.size() > k){
						isOkay = true;
						break;
					}
				}
			}
		}
		total = total%p;
		pw.println(total);
		pw.close();
	}
}

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class b {

	static class N
	{
		ArrayList<Integer> digits = new ArrayList<>();

		public int add(int index)
		{
			if(index == -1)
			{
				digits.add(0, 1);
				return 1;
			}

			if(digits.get(index) == 9)
			{
				int move = add(index-1);
				digits.set(index+move, 0);
				return move;
			}

			digits.set(index, digits.get(index)+1);
			return 0;
		}

		public long val()
		{
			long ret = 0;
			long mult = 1;

			for(int i=0; i<digits.size(); i++)
			{
				ret +=	digits.get(i)*mult;
				mult *= 10;
			}

			for(int i=digits.size()-1; i>=0; i--)
			{
				ret +=	digits.get(i)*mult;
				mult *= 10;
			}

			return ret;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int count = in.nextInt();
		int mod = in.nextInt();

		N build = new N();

		long out = 0;
		for(int i=0; i<count; i++)
		{
			build.add(build.digits.size()-1);
			out = (out + build.val())%mod;
		}
		System.out.println(out);
	}

//	public static int go(StringBuilder number, int mod, boolean isFirst)
//	{
//		if(made >= count) return 0;
//
//
//
//		i = 0;
//		if(isFirst) i = 1;
//		for(; i<9; i++)
//		{
//			number.append(i+'0');
//			ret = (ret + go(number, mod, false))%mod;
//			number.deleteCharAt(number.length()-1);
//			made++;
//			if(made >= count) return ret;
//		}
//
//		return ret;
//	}
//
//	public static int val(int number, boolean isFirst)
//	{
//
//		StringBuilder cpy = new StringBuilder(number.toString());
//
//		for(int i=number.length()-1; i>=0; i--)
//			cpy.append(number.charAt(i));
//
//		return Integer.valueOf(cpy.toString());
//	}

}

/*
20
11 + 22 + 33 + 44 + 55 + 66 + 77 + 88 + 99 + 1001 + 1111 + 1221 + 1331 + 1441 + 1551 + 1661 + 1771 + 1881 + 1991 + 2002

30
11 + 22 + 33 + 44 + 55 + 66 + 77 + 88 + 99 + 1001 + 1111 + 1221 + 1331 + 1441 + 1551 + 1661 + 1771 + 1881 + 1991 + 2002 + 2112 + 2222 + 2332 + 2442 + 2552 + 2662 + 2772 + 2882 + 2992 + 3003
 */

import java.util.Scanner;

public class Codeforces {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int k=in.nextInt();
		int p=in.nextInt();
		long sum=0;
		for(int i=1;i<=k;i++){
			String first=i+"";
			StringBuilder last=new StringBuilder(first).reverse();

			sum+=Long.parseLong(first+last);
			sum=sum%p;
		}

		System.out.println(sum);

	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] arr;
        Long k,p,counter=5L,answer=0L;
        arr = in.readLine().split(" ");
        counter = Long.valueOf(arr[0]);
        p = Long.valueOf(arr[1]);
        StringBuilder helpStr = new StringBuilder();
        for (int j = 1; j < 1000000; j*=10) {
            for (int i = j; i < 10*j; i++) {
                counter--;
                helpStr.append(i);
                helpStr.append((new StringBuffer(helpStr).reverse()));
                answer+=Long.valueOf(helpStr.toString());
                if (counter==0){
                    break;
                }
                helpStr.setLength(0);
            }
            if (counter==0){
                break;
            }
        }
        System.out.println(answer%p);
        //System.out.println(counter);
    }

}

	import java.util.ArrayList;
import java.util.Scanner;

public class B_449 {

	public static void main(String[]args) {
		Scanner input = new Scanner(System.in);
		int k = input.nextInt();
		int p=input.nextInt();
		findPalindromes(k,p);
	}
	public static void findPalindromes(int k, int p) {
		ArrayList<Long> pal = new ArrayList<Long>();
		int even = 1;
		String s="";
		while(pal.size()<k) {
			String curr=Integer.toString(even);
			String rev = reverse(curr);
			even++;
			s=curr + rev;
			pal.add(Long.parseLong(s));
		}
		long sum=0;
		for(int i=0; i<pal.size();i++) {
			sum=sum+pal.get(i);
			sum %= p;
		}
		System.out.println(sum);
	}

	public static String reverse(String s) {
		String newS="";
		for(int e=s.length()-1; e>=0;e--) {
			newS = newS+s.charAt(e);
		}
		return newS;
	}
}

import java.util.Scanner;

public class Eieve {

    public static void main(String args[]) {

        Scanner input = new Scanner(System.in);

        long k = input.nextLong(), p = input.nextLong();
        long j = 0, i1 = 0, sum = 0, c = 1, j1 = 0;

        for (int i = 1; i <= k; i++) {
            j = i;
            j1 = i;
            while (j1 > 0) {

                j = j * 10 + j1 % 10;
                //System.out.println(i1);
                j1 = j1 / 10;

            }
            //System.out.println(j);
            //String x=Long.toString(i1);
            //StringBuilder s=new StringBuilder(i1);
            //if(s.length()%2==0){
            sum = sum + j;
            //c++;
            //i1=0;

        }//else{
        //k++;
        //}
        System.out.println(sum % p);
    }

}

//package B;
/**
 * Created by Eesaa on 12/5/2017.
 */

import java.util.*;

public class B_897 {
    public static void main(String [] args){
        Scanner sc =new Scanner(System.in);int k = sc.nextInt(); int p = sc.nextInt();
        long sum = 0;
        for(int i = 1; i <= k; i++){
            int icopy = i;
            long sumi = i;
            while(icopy>0){
                sumi = (sumi*10)+(icopy%10);
                icopy /=10;
            }
            sum +=sumi;
        }
        System.out.print(sum%p);
    }

}

/**
 * Date: 14 Mar, 2018
 * Link :
 *
 * @author Prasad-Chaudhari
 * @email prasadc8897@gmail.com
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class New_File_3 {

    public static void main (String[] args) throws java.lang.Exception {
        FastIO2 in = new FastIO2();
        int k = in.ni();
        int p = in.ni();
        long a[] = new long[2*k+2];
        a[1]=1;
        for(int i=2;i<=2*k+1;i++){
            a[i] = (a[i-1]*10)%p;
        }
        long ans = 0;
        for(int i=1;i<=k;i++){
            char c[]  = (i+"").toCharArray();
            for(int j=0;j<c.length;j++){
                ans += ((c[c.length-j-1]-'0')*(a[c.length+j+1]+a[c.length-j]))%p;
                ans%=p;
            }
        }
        System.out.println(ans);
    }

    static class FastIO2 {

        private final BufferedReader br;
        private String s[];
        private int index;

        public FastIO2() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            index = 0;
        }

        public int ni() throws IOException {
            return Integer.parseInt(nextToken());
        }

        public double nd() throws IOException {
            return Double.parseDouble(nextToken());
        }

        public long nl() throws IOException {
            return Long.parseLong(nextToken());
        }

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            return br.readLine();
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if(s == null){
                s = br.readLine().split(" ");
            }
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ouheguaughwugfyuwgfiuqwgr
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static ArrayList<Long> list = new ArrayList<>();

        public void solve(int testNumber, InputReader scan, OutputWriter out) {
//        ArrayList<Long> list = new ArrayList<>();
            for (int i = 1; i <= 6; ++i) {
                generate(i - 1, "", i - 1);
//            out.println(i);
            }
            Collections.sort(list);
            long ans = 0;
            int k = scan.nextInt();
            long mod = scan.nextLong();
            for (int i = 0; i < k; ++i) {
                ans = (ans + list.get(i)) % mod;
//            out.println(list.get(i));
            }
            out.println(ans);
        }

        void generate(int n, String s, int length) {
//        System.out.println(n);
            if (n < 0) return;
            for (int i = 0; i <= 9; ++i) {
                String t = "";
                if (i == 0 && n == length) continue;
                t = s + Integer.toString(i);
                if (n == 0) {
                    StringBuilder sb = new StringBuilder(t);
                    sb.reverse();
                    t += sb.toString();
                    list.add(Long.parseLong(t));
                } else {
                    generate(n - 1, t, length);
                }
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.*;
public class Task897B {
	static long k, p;
	static long[] pow = new long[12];
	static long go(int t){
		int dig = (int) (Math.log10(t)+1);
		long ret = 0;
		long ten = 1;
		for(int i = 0; i < dig; i++){
			ret += ((t/ten) % 10) * (pow[dig - i - 1] + pow[dig + i]);

			ret  %= p;
			ten *= 10;
		}
		return ret;

	}
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		k = sc.nextLong();
		p = sc.nextLong();
		long ret = 0;
		pow[0] = 1;
		for(int i = 1; i < 12; i++)
			pow[i] = (pow[i-1] * 10) % p;
		for(int i = 1; i <= k; i++){
			ret += go(i);
			ret %= p;
		}
		System.out.print(ret);

	}
}

import java.util.*;
import java.io.*;

public class Chthollys_request {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int k = Integer.parseInt(st.nextToken());
		int p = Integer.parseInt(st.nextToken());
		long sum = 0;
		String s = "";
		for (int i = 1; i <= k; i++) {
			StringBuilder s1 = new StringBuilder(i + "");
			StringBuilder s2 = new StringBuilder(i + "");
			s2.reverse();
			s1.append(s2);
			s = s1.toString();
			//System.out.println(s);
			sum += Long.parseLong(s);
		}
		pw.println(sum % p);
		pw.flush();
		pw.close();
	}
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int p = in.nextInt();
        long sum = 0;
        for (int i = 1; i <= k; i++) {
            String str = Integer.toString(i);
            StringBuilder strB = new StringBuilder(str).append(new StringBuilder(str).reverse());
            long tmp = Long.parseLong(strB.toString());
            sum += tmp;
            sum %= p;
        }
        System.out.print(sum);
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextInt();
        long p = sc.nextInt();
        long c = 0;
        for(long i=1;i<=k;i++)
        {
            String temp = "";
            temp = String.valueOf(i);
            StringBuilder sb = new StringBuilder(temp).reverse();
            String temp1 = sb.toString();
            temp = temp+temp1;
            long s = Long.parseLong(temp);
            c = c + s;
        }
        System.out.println(c%p);
    }
}

import java.io.*;
import java.util.*;
public class CF897_D2_B{
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);

		int k=sc.nextInt();
		int p=sc.nextInt();

		long ans=0;
		Queue<String> q=new LinkedList<String>();
		q.add("");
		int c=-1;
		while(c<k){
			String s=q.poll();
			String s1=s.substring(0, s.length()/2);
			String s2=s.substring(s.length()/2);
			if(!s.equals("00"))
				for(int i=0;i<=9;i++)
					q.add(s1+i+i+s2);
			if(!s.equals("")){
				ans+=Long.parseLong(s);
				ans%=p;
				c++;
			}
		}
		pw.println(ans);
		pw.flush();
		pw.close();
	}

	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}

import java.io.*;
import java.util.*;

public class Solution{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int P = sc.nextInt();

    System.out.println(compute(K, P));
  }

  public static int compute(int K, int P){
    char[] num = {'1', '1'};
    int total = 0;
    while(K > 0){
      int i = num.length / 2 - 1;
      int j = num.length / 2;

      long curr = Long.parseLong(new String(num));
      total = (total + (int)(curr % P)) % P;
      // System.out.println("Test: " + curr);
      // System.out.println(P);
      // System.out.println(total);
      K--;

      while(i >= 0 && j < num.length && num[i] == '9' && num[j] == '9'){
        num[i--] = '0';
        num[j++] = '0';
      }

      // All digits are 9's
      if(i < 0 || j >= num.length){
        char[] temp = new char[num.length + 2];
        temp[0] = '1';
        temp[num.length+1] = '1';

        for(int k = 1; k < num.length+1; k++){
          temp[k] = '0';
        }

        num = temp;

      } else {

        // find next zcy number
        num[i]++;
        num[j]++;
      }
    }

    return total;

  }

}

	/*	/ ﾌﾌ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム
		/ )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀  Y
		(⠀⠀| ( ͡° ͜ʖ ͡°）⠀⌒(⠀ ノ
		(⠀ ﾉ⌒ Y ⌒ヽ-く __／
		| _⠀｡ノ| ノ｡ |/
		(⠀ー '_人`ー ﾉ
		⠀|\ ￣ _人'彡ﾉ
		⠀ )\⠀⠀ ｡⠀⠀ /
		⠀⠀(\⠀ #⠀ /
		⠀/⠀⠀⠀/ὣ====================D-
		/⠀⠀⠀/⠀ \ \⠀⠀\
		( (⠀)⠀⠀⠀⠀ ) ).⠀)
		(⠀⠀)⠀⠀⠀⠀⠀( | /
		|⠀ /⠀⠀⠀⠀⠀⠀ | /
		[_] ⠀⠀⠀⠀⠀[___]                     */
	// Main Code at the Bottom
	import java.util.*;
	import java.lang.*;
	import java.io.*;
	import java.math.BigInteger;
	public class Main {
		//Fast IO class
	    static class FastReader {
	        BufferedReader br;
	        StringTokenizer st;
	        public FastReader() {
	        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
	        	if(!env) {
	        		try {
						br=new BufferedReader(new FileReader("src\\input.txt"));
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
	        	}
	        	else br = new BufferedReader(new InputStreamReader(System.in));
	        }
	        String next() {
	            while (st == null || !st.hasMoreElements()) {
	                try {
	                    st = new StringTokenizer(br.readLine());
	                }
	                catch (IOException  e) {
	                    e.printStackTrace();
	                }
	            }
	            return st.nextToken();
	        }
	        int nextInt() {
	            return Integer.parseInt(next());
	        }
	        long nextLong() {
	            return Long.parseLong(next());
	        }
	        double nextDouble() {
	            return Double.parseDouble(next());
	        }
	        String nextLine() {
	            String str = "";
	            try {
	                str = br.readLine();
	            }
	            catch (IOException e) {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	    static long MOD=1000000000+7;
	    //Euclidean Algorithm
	    static long gcd(long A,long B){
	    	return (B==0)?A:gcd(B,A%B);
	    }
	    //Modular Exponentiation
	    static long fastExpo(long x,long n){
	        if(n==0) return 1;
	        if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
	        return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
	    }
	    //Modular Inverse
	    static long inverse(long x) {
	    	return fastExpo(x,MOD-2);
	    }
	    //Prime Number Algorithm
	    static boolean isPrime(long n){
	        if(n<=1) return false;
	        if(n<=3) return true;
	        if(n%2==0 || n%3==0) return false;
	        for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;
	        return true;
	    }
	    //Reverse an array
	    static void reverse(char arr[],int l,int r){
	    	while(l<r) {
	    		char tmp=arr[l];
	    		arr[l++]=arr[r];
	    		arr[r--]=tmp;
	    	}
	    }
	    //Print array
	    static void print1d(int arr[]) {
	    	out.println(Arrays.toString(arr));
	    }
	    static void print2d(int arr[][]) {
	    	for(int a[]: arr) out.println(Arrays.toString(a));
	    }
	    // Pair
	    static class pair{
	    	int x,y;
	    	pair(int a,int b){
	    		this.x=a;
	    		this.y=b;
	    	}
	    	public boolean equals(Object obj) {
	    		if(obj == null || obj.getClass()!= this.getClass()) return false;
	            pair p = (pair) obj;
	            return (this.x==p.x && this.y==p.y);
	        }
	    	public int hashCode() {
	            return Objects.hash(x,y);
	        }
	    }
	    static FastReader sc=new FastReader();
	    static PrintWriter out=new PrintWriter(System.out);
	    //Main function(The main code starts from here
	    public static void main (String[] args) throws java.lang.Exception {
	    	int test=1;
	    	//test=sc.nextInt();
	    	while(test-->0){
	    		int n=sc.nextInt();
	    		long p=sc.nextLong(),sum=0;
	    		for(int i=1;i<=n;i++) {
	    			StringBuilder a=new StringBuilder(i+"");
	    			long val=Long.parseLong((a+""+a.reverse()));
	    			sum=(sum%p+val%p)%p;
	    		}
	    		out.println(sum);
	    	}
	        out.flush();
	        out.close();
	    }
	}

import java.util.ArrayList;
import java.util.Scanner;

public class bb {
	static ArrayList<Integer> elm;
	public static long gen(int mod, int size) {
	elm =new ArrayList<Integer>();
		long sum = 0;
		for(int i = 11;i<=99;i+=11) {
			elm.add(i);
			sum= (sum%mod+i%mod)%mod;
			if(elm.size()==size)
				return (int)sum;
		}
		for(int i = 1001;i<=9999;i++) {
			String cur = i+"";
			boolean yes = true;
			for (int j = 0; j < cur.length()/2; j++) {
				if(cur.charAt(j)!=cur.charAt(cur.length()-1-j)) {
					yes = false;
					break;
				}
			}
			if(!yes)
				continue;
			elm.add(i);
			sum= (sum%mod+i%mod)%mod;
			//System.out.println(elm.size());
			if(elm.size()==size)
				return (int)sum;

		}
		long inner = 1100;
		long inner2 =10010;
		long inner3 = 100001;
		int count1 = 0;
		int count2 = 0;
		int count3 = 1;
		while(true) {
			long cur = count1*inner+count2*inner2+count3*inner3;
		//	System.out.println(cur);
			elm.add((int)cur);
			sum= (sum%mod+cur%mod)%mod;
		//	System.out.println(elm.size());
			if(elm.size()==size)
				return (int)sum;
			count1++;
			if(count1==10&&count2==9&&count3==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					count2=0;
				}
				count1=0;
			}
		}
		inner = 11000;
		inner2 =100100;
		inner3=1000010;
		long inner4= 10000001;
		count1 = 0;
		count2 = 0;
		count3= 0;
		int count4=1;
		while(true) {
			long cur = count1*inner+count2*inner2+count3*inner3+count4*inner4;

			elm.add((int)cur);
			sum= (sum%mod+cur%mod)%mod;
		//	System.out.println(cur);
			if(elm.size()==size)
				return (int)sum;

			count1++;
			if(count1==10&&count2==9&&count3==9&&count4==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					if(count3==10) {
						count3=0;
						count4++;
					}
					count2=0;
				}
				count1=0;
			}

		}
		long inner5 =1000000001;
		inner = 110000;
		inner2 =1001000;
		inner3 = 10000100;
		inner4 = 100000010;
		int count5 =1;
		count4=0;
		count3=0;
		count1=0;
		count2=0;
//		System.out.println(elm.size());
		while(true) {
			long cur = count1*inner+count2*inner2+count3*inner3+count4*inner4+count5*inner5;

			elm.add((int)cur);
			sum= (sum%mod+cur%mod)%mod;
		//	System.out.println(cur);
			if(elm.size()==size)
				return (int)sum;

			count1++;//
			if(count1==10&&count2==9&&count3==9&&count4==9&&count4==9&&count5==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					if(count3==10) {
						count3=0;
						count4++;
						if(count4==10) {
							count4=0;
							count5++;
						}
					}
					count2=0;
				}
				count1=0;
			}

		}
		//System.out.println("hello"+" "+elm.size());
		sum = (sum%mod+100000000001l%mod)%mod;
		return sum;

	}
public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int k = sc.nextInt();
	int p = sc.nextInt();

	System.out.println(gen(p,k));

}
}

import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	public static void main(String[] args) {
		FastScanner input = new FastScanner(System.in);

		int K = input.nextInt();
		int MOD = input.nextInt();

		long sum = 0;

		for (long i = 1; i <= K; i++) {
			long number = 0;
			long mold = 10;
			while (mold <= i)
				mold *= 10;
			number += mold * i;
			long copy = i;
			mold /= 10;
			while (mold > 0 && copy > 0) {
				number += mold * (copy % 10);
				mold /= 10;
				copy /= 10;
			}

			sum = (sum + number) % MOD;
		}

		System.out.println(sum);
	}

	// Matt Fontaine's Fast IO
	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

/**
 * Created by Chirag on 12-12-2017.
 * DA-IICT (B.tech 3rd year)
 */

import java.io.*;
import java.util.*;

public class ChotllyRequest
{
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

      /*
      int n      = sc.nextInt();        // read input as integer
      long k     = sc.nextLong();       // read input as long
      double d   = sc.nextDouble();     // read input as double
      String str = sc.next();           // read input as String
      String s   = sc.nextLine();       // read whole line as String

      int result = 3*n;
      out.println(result);                    // print via PrintWriter
      */
        //The Code Starts here
        int k=sc.nextInt();
        int p=sc.nextInt();
        int noOfNumbers=0;
        long sum=0;
        int i=1;
        while (noOfNumbers<k)
        {
            int num=i;
            StringBuilder revNum=new StringBuilder(Integer.toString(num));
            revNum.reverse();
            StringBuilder orgNum=new StringBuilder(Integer.toString(num));
//            debug(orgNum,revNum);
            sum=(sum+(Long.parseLong(orgNum.append(revNum).toString()))%p)%p;
            noOfNumbers++;
            i++;
        }
        out.print(sum);

        //The Code ends here
        out.close();
    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextCharacter() {
            return next().charAt(0);
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        public int[][] nextInt2DArray(int m, int n) {
            int[][] arr = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++)
                    arr[i][j] = nextInt();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

    public static class Pair implements Comparable<Pair> {
        long u;
        long v;

        public Pair(long u, long v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
    //--------------------------------------------------------

    // Different other methods

    public static long pow(long n, long p, long mod) {
        if (p == 0)
            return 1;
        if (p == 1)
            return n % mod;
        if (p % 2 == 0) {
            long temp = pow(n, p / 2, mod);
            return (temp * temp) % mod;
        } else {
            long temp = pow(n, p / 2, mod);
            temp = (temp * temp) % mod;
            return (temp * n) % mod;

        }
    }

    public static long pow(long n, long p) {
        if (p == 0)
            return 1;
        if (p == 1)
            return n;
        if (p % 2 == 0) {
            long temp = pow(n, p / 2);
            return (temp * temp);
        } else {
            long temp = pow(n, p / 2);
            temp = (temp * temp);
            return (temp * n);

        }
    }

    public static long gcd(long x, long y) {
        if (x == 0)
            return y;
        else
            return gcd(y % x, x);
    }

    static long modInverse(long a, long m) {
        long m0 = m, t, q;
        long x0 = 0, x1 = 1;

        if (m == 1)
            return 0;

        while (a > 1) {
            // q is quotient
            q = a / m;

            t = m;

            // m is remainder now, process
            // same as Euclid's algo
            m = a % m;
            a = t;

            t = x0;

            x0 = x1 - q * x0;

            x1 = t;
        }

        // Make x1 positive
        if (x1 < 0)
            x1 += m0;

        return x1;
    }

    public static boolean isPrime(int n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

    public static class DisjointSet {
        HashMap<Integer, Node> map = new HashMap<Integer, Node>();

        class Node {
            int data;
            int rank;
            Node parent;

            Node(int data) {
                this.data = data;
                this.rank = 0;
                this.parent = this;
            }
        }

        void makeSet(int data) {
            map.put(data, new Node(data));
        }

        Node findSet(int data) {
            return findSet(map.get(data));
        }

        boolean isConnected(int d1, int d2) {
            return findSet(d1) == findSet(d2);
        }

        Node findSet(Node node) {
            Node parent = node.parent;
            if (parent == node)
                return parent;
            node.parent = findSet(node.parent);
            return node.parent;
        }

        void union(int data1, int data2) {
            Node d1 = map.get(data1);
            Node d2 = map.get(data2);

            Node p1 = findSet(d1);
            Node p2 = findSet(d2);

            if (p1.data == p2.data)
                return;

            if (p1.rank >= p2.rank) {
                p1.rank = (p1.rank == p2.rank) ? p1.rank + 1 : p1.rank;
                p2.parent = p1;
            } else {
                p1.parent = p2;
            }
        }

    }

}

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class B {

	int len(int n) {
		return (""+n).length();
	}

	boolean isPalin(int n) {
		String s = ""+n;
		for(int i = 0, j = s.length() - 1; i <= j; ++i, --j) {
			if(s.charAt(i) != s.charAt(j)) return false;
		}
		return true;
	}

	String rev(long n) {
		String srev = new StringBuilder(""+n).reverse().toString();
		return srev;
	}

	long makeNum(long a, String b) {
		return Long.parseLong(""+a+b);
	}

	public void solve(Scanner in, PrintWriter out) {
		ArrayList<Long> evenPalins = new ArrayList<>();
		for(long i = 1; i <= 101000; ++i) {
			long newNum = makeNum(i, rev(i));
			evenPalins.add(newNum);
		}
		long[] sum = new long[evenPalins.size()];
		for(int i = 0; i < evenPalins.size(); ++i) {
			sum[i] = evenPalins.get(i);
			if(i > 0) sum[i] += sum[i - 1];
		}
		int n = in.nextInt();
		int p = in.nextInt();
		out.println(sum[n - 1] % p);
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		new B().solve(in, out);

		in.close();
		out.close();
	}
}

import java.util.*;
import java.text.*;
import java.io.*;
import java.math.*;
public class code5 {
	InputStream is;
	PrintWriter out;
	static long mod=pow(10,9)+7;
	static int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
	void solve() throws IOException
	{
		int n=ni();
		int p=ni();
		long sum=0;
		for(int i=1;i<=n;i++)
		{
			int num=i,len=0;
			while(num!=0)
			{
				num/=10;
				len++;
			}
			num=i;
			int templen=len;
			while(num!=00)
			{
				sum+=pow(10,templen++)*(num%10);
				num/=10;
			}
			num=i;
			while(num!=0)
			{
				sum+=pow(10,--len)*(num%10);
				num/=10;
			}
		}
		out.print(sum%p);
	}
	ArrayList<Integer> al[];
 	void take(int n,int m)
 	{
 		al=new ArrayList[n];
 		for(int i=0;i<n;i++)
 			al[i]=new ArrayList<Integer>();
 		for(int i=0;i<m;i++)
 		{
 			int x=ni()-1;
 			int y=ni()-1;
 			al[x].add(y);
 			al[y].add(x);
 		}
 	}
 	int check(long n)
 	{
 		int count=0;
 		while(n!=0)
 		{
 			if(n%10!=0)
 				break;
 			n/=10;
 			count++;
 		}
 		return count;
 	}
	public static int count(int x)
	{
		int num=0;
		while(x!=0)
		{
			x=x&(x-1);
			num++;
		}
		return num;
	}
	static long d, x, y;
	void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	long modInverse(long A,long M) //A and M are coprime
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}
	public static void mergeSort(int[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(int arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		int left[] = new int[n1];
		int right[] = new int[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	public static void mergeSort(long[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(long arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		long left[] = new long[n1];
		long right[] = new long[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	 static class Pair implements Comparable<Pair>{

	       int x,y,k;
	       int i,dir;
	       long val;
		Pair (int x,int y){
			this.x=x;
			this.y=y;
		}
		public int compareTo(Pair o) {
			return this.x-o.x;
		}

		public String toString(){
			return x+" "+y+" "+k+" "+i;}
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair)o;
				return p.x == x && p.y == y;
			}
			return false;
		}
		public int hashCode() {
			return new Long(x).hashCode()*31 + new Long(y).hashCode() ;
		}
	}

	    public static boolean isPal(String s){
	        for(int i=0, j=s.length()-1;i<=j;i++,j--){
	                if(s.charAt(i)!=s.charAt(j)) return false;
	        }
	        return true;
	    }
	    public static String rev(String s){
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
	    }

	    public static long gcd(long x,long y){
		if(y==0)
			return x;
		else
			return gcd(y,x%y);
	    }

	    public static int gcd(int x,int y){
	    	if(y==0)
	    		return x;
	    	return gcd(y,x%y);
	    }

	    public static long gcdExtended(long a,long b,long[] x){

	        if(a==0){
	            x[0]=0;
	            x[1]=1;
	            return b;
	        }
	        long[] y=new long[2];
	        long gcd=gcdExtended(b%a, a, y);

	        x[0]=y[1]-(b/a)*y[0];
	        x[1]=y[0];

	        return gcd;
	    }

	    public static int abs(int a,int b){
		return (int)Math.abs(a-b);
	    }

	    public static long abs(long a,long b){
		return (long)Math.abs(a-b);
	    }

	    public static int max(int a,int b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static int min(int a,int b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long max(long a,long b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static long min(long a,long b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long pow(long n,long p,long m){
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	    }

	    public static long pow(long n,long p){
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;
	    }
	    public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
	    void run() throws Exception {
			is = System.in;
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		}

	    public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
				public void run() {
					try {
						new code5().run();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();

	    	//new code5().run();
		}
	    private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b));
			return b;
		}

		private double nd() {
			return Double.parseDouble(ns());
		}

		private char nc() {
			return (char) skip();
		}

		private String ns() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = ns(m);
			return map;
		}

		private int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = ni();
			return a;
		}
		private long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nl();
			return a;
		}

		private int ni() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B449 solver = new B449();
        solver.solve(1, in, out);
        out.close();
    }

    static class B449 {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int k = in.scanInt();
            int p = in.scanInt();

            long ans = 0;
            for (int i = 1; i <= k; i++) {
                String str = String.valueOf(i);
                String revstr = new StringBuffer(str).reverse().toString();

                str = str.concat(revstr);
                ans += (Long.parseLong(str));
            }

            System.out.println(ans % p);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                    ;
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

import java.util.Arrays;
import java.util.Scanner;

public class B_449 {

	public static String getnum(int num) {
		String s = Integer.toString(num);
		int i = s.length()-1;
		StringBuilder sb = new StringBuilder();
		for(int j = i; j >= 0 ; j--) {
			sb.append(s.charAt(j));
		}
		StringBuilder rev = new StringBuilder();
		for(int k = 0; k <= i; k++) {
			rev.append(s.charAt(k));
		}

		return rev.toString()+sb.toString();
	}

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int k = scn.nextInt();
		int p = scn.nextInt();

		long res = 0;
		for(int i = 1; ; i++) {
			if(k == 0) break;
//			System.out.println(i+" ** ");
			long n = Long.parseLong(getnum(i));
//			System.out.println(n+" -- ");
			res += n;
			res %= p;
			k--;
		}
		System.out.println(res);

	}

}

import java.io.*;
import java.util.*;

public class Solution {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong(), p = scanner.nextLong(), result = 0;
		for (int i = 1; i < n + 1; i++) {
		    String st = String.valueOf(i);
		    st  += new StringBuilder(st).reverse();
		    result += Long.parseLong(st)%p;
		}
		System.out.printf("%d", result % p);
	}
}

import java.util.*;
import java.io.*;

		public class codeforces
		{
			public static void main(String[] args)
			{
				InputReader in = new InputReader(System.in);
				PrintWriter pw = new PrintWriter(System.out);

				int k = in.nextInt();
				int m = in.nextInt();
				int count = 1;
				String f, b, p;
				long ans = 0;

				while(k>0)
				{
					f = Integer.toString(count);
					b = new StringBuilder(f).reverse().toString();

					p = f + b;

					ans += Long.parseLong(p);
					ans %= m;

					count++;
					k--;
				}

				pw.println(ans);

				pw.flush();
				pw.close();
			}

			public static long modularExponentiation(long x,long n,long M)
			{
			    long result=1;
			    while(n>0)
			    {
			        if(n % 2 ==1)
			            result=(result * x)%M;
			        x=(x*x)%M;
			        n=n/2;
			    }
			    return result;
			}

			static class pair implements Comparable<pair>
			{
				Integer x, y;
				pair(int x,int y)
				{
					this.x=x;
					this.y=y;
				}

				public int compareTo(pair o) {
					int result = x.compareTo(o.x);
					if(result==0)
						result = y.compareTo(o.y);

					return result;
				}

				public String toString()
				{
					return x+" "+y;
				}

				public boolean equals(Object o)
				{
					if (o instanceof pair)
				    {
						pair p = (pair)o;
						return p.x == x && p.y == y ;
					}
					return false;
				}

				public int hashCode()
				{
					return new Long(x).hashCode()*31 + new Long(y).hashCode();
				}
			}

			static class InputReader
			{

				private final InputStream stream;
				private final byte[] buf = new byte[8192];
				private int curChar, snumChars;
				private SpaceCharFilter filter;

				public InputReader(InputStream stream)
				{
					this.stream = stream;
				}

				public int snext()
				{
					if (snumChars == -1)
						throw new InputMismatchException();
					if (curChar >= snumChars)
					{
						curChar = 0;
						try
						{
							snumChars = stream.read(buf);
						}
						catch (IOException e)
						{
							throw new InputMismatchException();
						}
						if (snumChars <= 0)
							return -1;
					}
					return buf[curChar++];
				}

				public int nextInt()
			    {
					int c = snext();
					while (isSpaceChar(c))
					{
						c = snext();
					}
					int sgn = 1;
					if (c == '-')
				    {
						sgn = -1;
						c = snext();
					}
					int res = 0;
					do
					{
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = snext();
					} while (!isSpaceChar(c));
					return res * sgn;
				}

				public long nextLong()
			    {
					int c = snext();
					while (isSpaceChar(c))
					{
						c = snext();
					}
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = snext();
					}
					long res = 0;
					do
					{
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = snext();
					} while (!isSpaceChar(c));
					return res * sgn;
				}

				public int[] nextIntArray(int n)
				{
					int a[] = new int[n];
					for (int i = 0; i < n; i++)
					{
						a[i] = nextInt();
					}
					return a;
				}

				public String readString()
			    {
					int c = snext();
					while (isSpaceChar(c))
					{
						c = snext();
					}
					StringBuilder res = new StringBuilder();
					do
					{
						res.appendCodePoint(c);
						c = snext();
					} while (!isSpaceChar(c));
					return res.toString();
				}

				public String nextLine()
				{
					int c = snext();
					while (isSpaceChar(c))
						c = snext();
					StringBuilder res = new StringBuilder();
					do
					{
						res.appendCodePoint(c);
						c = snext();
					} while (!isEndOfLine(c));
					return res.toString();
				}

				public boolean isSpaceChar(int c)
				{
					if (filter != null)
						return filter.isSpaceChar(c);
					return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
				}

				private boolean isEndOfLine(int c)
				{
					return c == '\n' || c == '\r' || c == -1;
				}

				public interface SpaceCharFilter
			    {
					public boolean isSpaceChar(int ch);
				}
			}

			/*static class CodeX {
	        public static void sort(long arr[]) {
	            merge_sort(arr, 0, arr.length - 1);
	        }

	        private static void merge_sort(long A[], long start, long end) {
	            if (start < end) {
	                long mid = (start + end) / 2;
	                merge_sort(A, start, mid);
	                merge_sort(A, mid + 1, end);
	                merge(A, start, mid, end);
	            }

	        }

	        private static void merge(long A[], long start,long mid, long end) {
	            long p = start, q = mid + 1;
	            long Arr[] = new long[(int)(end - start + 1)];
	            long k = 0;

	            for (int i = (int)start; i <= end; i++) {
	                if (p > mid)
	                    Arr[(int)k++] = A[(int)q++];

	                else if (q > end)
	                    Arr[(int)k++] = A[(int)p++];

	                else if (A[(int)p] < A[(int)q])
	                    Arr[(int)k++] = A[(int)p++];

	                else
	                    Arr[(int)k++] = A[(int)q++];
	            }
	            for (int i = 0; i < k; i++) {
	                A[(int)start++] = Arr[i];
	            }

	        }

	    }*/
		}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Try
{

    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}

		public String rs() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

    static long mod=1000000007;
    static BigInteger bigInteger = new BigInteger("1000000007");
    static int n = (int)1e6;
    static boolean[] prime;
    static ArrayList<Integer> as;
    static void sieve() {
			Arrays.fill(prime	, true);
			prime[0] = prime[1] = false;
			for(int i = 2 ; i * i <= n ; ++i) {
				if(prime[i]) {
					for(int k = i * i; k< n ; k+=i) {
						prime[k] = false;
					}
				}
			}

		}
		static PrintWriter w = new PrintWriter(System.out);
 static char [][]sol;
    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        //PrintWriter w = new PrintWriter(System.out);

       /*
        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;
		*/
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));
            */

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

    // Student []st = new Student[x];
   // st[i] = new Student(i,d[i]);
     //Arrays.sort(st,(p,q)->p.diff-q.diff);

int k = sc.ni();
int p = sc.ni();
int r = 0;
BigInteger b2 = new BigInteger("0");
for(int i=1;i<=k;i++)
{
   String q = ips(i);
   StringBuilder sb1 = new StringBuilder(q);
   StringBuilder sb = new StringBuilder(q);
   sb.reverse();

   String temp = sb.toString();
   sb1.append(temp);
   String t1 = sb1.toString();
  BigInteger b1 = new BigInteger(t1);
  b2 = b2.add(b1);

}
 String h = ips(p);
 BigInteger b3 = new BigInteger(h);
 b2 = b2.mod(b3);
     w.println(b2);

      w.close();

    }

     static class Student
    {

        long first;
        long sec;
        Student(long first,long sec)
        {
            this.first = first;
            this.sec = sec;

        }

    }

     public static long modMultiply(long one, long two) {

		return (one % mod * two % mod) % mod;
	}
    static long fx(int m)
    {
        long re = 0;
        for(int i=1;i<=m;i++)
        {
            re += (long) (i / gcd(i,m));
        }
        return re;
    }
     static long gcd(long a, long b)
    {
	 if (a == 0)
	  return b;

	return gcd(b%a, a);
    }

     static long phi(long nx)
    {
        // Initialize result as n
        double result = nx;

        // Consider all prime factors of n and for
        // every prime factor p, multiply result
        // with (1 - 1/p)
        for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
        {
            // Check if p is a prime factor.
            if (nx % as.get(p) == 0)
            {
                // If yes, then update n and result
                while (nx % as.get(p) == 0)
                    nx /= as.get(p);
                result *= (1.0 - (1.0 / (double) as.get(p)));
            }
        }

        // If n has a prime factor greater than sqrt(n)
        // (There can be at-most one such prime factor)
        if (nx > 1)
            result *= (1.0 - (1.0 / (double) nx));

        return (long)result;

        //return(phi((long)result,k-1));

    }

    public static int primeFactors(int n,int x)
    {
        as = new ArrayList<>();
        int sum = 0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {

            if(sum == x-1)
                break;
            as.add(2);
            //System.out.print(2 + " ");
            n /= 2;
            sum++;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {

               // System.out.print(i + " ");
                if(sum == x-1)
                break;
                as.add(i);
                n /= i;
                sum++;

            }

        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n >= 2)
        {
            sum++;
            as.add(n);
        }
            return sum;
    }
    static int digitsum(int x)

    {

        int sum = 0;
        while(x > 0)
        {
            int temp = x % 10;
            sum += temp;
            x /= 10;
        }
        return sum;

    }
    static int countDivisors(int n)
    {
        int cnt = 0;
        for (int i = 1; i*i <=n; i++)
        {
             if (n % i == 0 && i<=1000000)
             {
                // If divisors are equal,
                // count only one
                if (n / i == i)
                   cnt++;

                else // Otherwise count both
                    cnt = cnt + 2;
             }
         }
        return cnt;
    }

    static boolean isprime(int n)
    {

    if(n == 2)
        return true;
    if(n == 3)
        return true;
    if(n % 2 == 0)
        return false;
    if(n % 3 == 0)
        return false;

    int i = 5;
   int w = 2;

    while(i * i <= n)
    {
        if(n % i == 0)
            return false;

        i += w;
        w = 6 - w;
    }

    return true;
    }

    static long log2(long value) {
    return Long.SIZE-Long.numberOfLeadingZeros(value);
}

    static boolean binarysearch(int []arr,int p,int n)
    {
        //ArrayList<Integer> as = new ArrayList<>();
        //as.addAll(0,at);
        //Collections.sort(as);
        boolean re = false;
        int st = 0;
        int end = n-1;

        while(st <= end)
        {
            int mid = st + (end-st)/2;

            if(p > arr[mid])
            {
                st = mid+1;

            }
            else if(p < arr[mid])
            {
                end = mid-1;

            }
            else if(p == arr[mid])
            {

            re = true;
            break;
            }

        }
         return re;

    }

    /* Java program for Merge Sort */
static class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    /* A utility function to print array of size n */

}

    public static int ip(String s){
		return Integer.parseInt(s);
	}

	 public static String ips(int s){
		return Integer.toString(s);
	}

}

import java.util.Scanner;

public class Main {

    static String rev(String s)
    {
        String res = "";
        for (int i = s.length()-1; i>=0; --i)
            res+= s.charAt(i);
        return  res;
    }
    static long gen(long left)
    {
        String s = ""+left;
        String r = rev(s);
         s = s+r;
        return  Long.parseLong(s);
    }

    static  long solve(int k, long mod)
    {
        long res = 0;
        for (long i = 1; i<= k; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i);
            res%= mod;
        }
        return  res;
    }

    public static void main(String[] args) {
        Scanner sc =  new Scanner(System.in);
        long res = 0;
        int k= sc.nextInt();
        int m = sc.nextInt();
        System.out.print(solve(k, m));
        // write your code here
    }
}

import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class Main implements Runnable {

	String file = "input";
    boolean TEST = System.getProperty("ONLINE_JUDGE") == null;

    void solve() throws IOException {
    	int k = nextInt(), p = nextInt();
    	long res = 0;
    	for (int i = 1; i <= k; i++) {
    		StringBuilder a = new StringBuilder(i + "");
    		a = (new StringBuilder(a)).append(a.reverse());
    		res += Long.parseLong(a.toString());
    		res %= p;
    	}
    	out.println(res);
    }

    String next() throws IOException {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    void debug(Object... o) {
        System.out.println(deepToString(o));
    }

    void gcj(Object o) {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException {
        if (TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

    public static void main(String[] args) throws IOException {
        new Thread(null, new Main(), "", 1 << 20).start();
    }

    public void run() {
        try {
            init();
            if (TEST) {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            } else solve();
            out.close();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author raghumdani
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt(), p = in.nextInt();

            int res = 0;

            for (int i = 1; i <= k; ++i) {
                int cnt = 0, n = i, nn = 0;
                while (n > 0) {
                    int cur = n % 10;
                    n /= 10;
                    cnt++;
                    nn = nn * 10 + cur;
                }

                res = NumberUtils.add(res, NumberUtils.mul(i, NumberUtils.power(10, cnt, p), p), p);
                res = NumberUtils.add(res, nn, p);
            }

            out.println(res);
        }

    }

    static class NumberUtils {
        public static int power(int a, int b, int mod) {
            int res = 1;

            while (b > 0) {
                if (b % 2 == 1)
                    res = mul(res, a, mod);
                a = mul(a, a, mod);
                b >>= 1;
            }

            return res;
        }

        public static int mul(int a, int b, int mod) {
            return (int) (((long) a * b) % mod);
        }

        public static int add(int a, int b, int mod) {
            if (a >= mod)
                a %= mod;
            if (b >= mod)
                b %= mod;
            int res = a + b;
            if (res >= mod)
                res -= mod;
            if (res < 0)
                res += mod;
            return res;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.util.*;
import java.io.*;

public class B_Chthollys_Request {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		int p = in.nextInt();
		double num = 0;
		int digit;
		String pali;

		for(int i = 1; i <= k; i++){
			pali = "";
			int mult = i;
			while(mult != 0){
				digit = mult%10;
				pali += digit;
				mult /= 10;
			}
			if((Integer.parseInt(pali) + 1)%10 == 1) continue;
			System.out.println(i + pali);
			num += Double.parseDouble(i + pali);

		}

		System.out.print((int)(num % p));

	}

}

/**
 * Date: 14 Mar, 2018
 * Link :
 *
 * @author Prasad-Chaudhari
 * @email prasadc8897@gmail.com
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class New_File_3 {

    public static void main (String[] args) throws java.lang.Exception {
        FastIO2 in = new FastIO2();
        int k = in.ni();
        int p = in.ni();
        long a[] = new long[2*k+2];
        a[1]=1;
        for(int i=2;i<=2*k+1;i++){
            a[i] = (a[i-1]*10)%p;
        }
        long ans = 0;
        for(int i=1;i<=k;i++){
            char c[]  = (i+"").toCharArray();
            for(int j=0;j<c.length;j++){
                ans += ((c[j]-'0')*(a[c.length+j+1]+a[c.length-j]))%p;
                ans%=p;
            }
        }
        ans%=p;
        System.out.println(ans);
    }

    static class FastIO2 {

        private final BufferedReader br;
        private String s[];
        private int index;

        public FastIO2() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            index = 0;
        }

        public int ni() throws IOException {
            return Integer.parseInt(nextToken());
        }

        public double nd() throws IOException {
            return Double.parseDouble(nextToken());
        }

        public long nl() throws IOException {
            return Long.parseLong(nextToken());
        }

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            return br.readLine();
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if(s == null){
                s = br.readLine().split(" ");
            }
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }
}

import java.io.*;
import java.util.*;

public class Solution {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong(), p = scanner.nextLong(), result = 0, cur = 0;
		for (int i = 0, j = 1; i < n; i++) {
		    String st = String.valueOf(j);
		    StringBuilder stb = new StringBuilder();
		    stb.append(st);
		    stb.reverse();
		    st += stb;
		    cur = Long.parseLong(st);
		    cur %= p;
		    result += cur;
		    result %= p;
		    j++;
		    st = String.valueOf(j);
		    for (int k = st.length() - 1; k >= 0; k--) {
		        if (st.charAt(k) == '0') {
		            j += Math.pow(10, st.length() - k - 1);
		        }
		    }
		}
		System.out.printf("%d", result);
	}
}

import java.util.ArrayList;
import java.util.Scanner;

public class palindrome {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		long b = scan.nextLong();
		int sum = 0;
		long s3 = 0;
		ArrayList<Long> arr = new ArrayList<Long>();
		for(int i =1;i<a+1;i++){
			String s = Integer.toString(i);
			String s1 = "";
			String s2 = "";
			for(int j =0;j<s.length();j++){
				s1 = s1+s.charAt(j);
			}
			for(int j =s.length();j>0;j--){
				s2 = s2+s.charAt(j-1);
			}
			s = s1+s2;

			s3 = Long.parseLong(s);
			arr.add(s3);

		}
		for(int i =0;i<arr.size();i++){
			sum+=arr.get(i);
		}
		System.out.println(sum%b);

	}

}

import java.util.Arrays;
import java.util.Scanner;

public class B_449 {

	public static String getnum(int num) {
		String s = Integer.toString(num);
		int i = s.length()-1;
		StringBuilder sb = new StringBuilder();
		for(int j = i; j >= 0 ; j--) {
			sb.append(s.charAt(j));
		}
		StringBuilder rev = new StringBuilder();
		for(int k = 0; k <= i; k++) {
			rev.append(s.charAt(k));
		}

		return rev.toString()+sb.toString();
	}

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int k = scn.nextInt();
		int p = scn.nextInt();

		long res = 0;
		for(int i = 1; i < 1000; i++) {
			if(k == 0) break;
//			System.out.println(i+" ** ");
			long n = Long.parseLong(getnum(i));
//			System.out.println(n+" -- ");
			res += n;
			res %= p;
			k--;
		}
		System.out.println(res);

	}

}

import java.util.ArrayList;
import java.util.Scanner;

public class bb {
	static ArrayList<Integer> elm;
	public static long gen(int mod, int size) {
	elm =new ArrayList<Integer>();
		long sum = 0;
		for(int i = 11;i<=99;i+=11) {
			elm.add(i);
			sum= (sum%mod+i%mod)%mod;
			if(elm.size()==size)
				return (int)sum;
		}
		for(int i = 1001;i<=9999;i++) {
			String cur = i+"";
			boolean yes = true;
			for (int j = 0; j < cur.length()/2; j++) {
				if(cur.charAt(j)!=cur.charAt(cur.length()-1-j)) {
					yes = false;
					break;
				}
			}
			if(!yes)
				continue;
			elm.add(i);
			sum= (sum%mod+i%mod)%mod;
			//System.out.println(elm.size());
			if(elm.size()==size)
				return (int)sum;

		}
		int inner = 1100;
		int inner2 =10010;
		int inner3 = 100001;
		int i = 100001;
		int count1 = 0;
		int count2 = 0;
		int count3 = 1;
		while(true) {
			int cur = count1*inner+count2*inner2+count3*inner3;
		//	System.out.println(cur);
			elm.add(cur);
			sum= (sum%mod+cur%mod)%mod;
		//	System.out.println(elm.size());
			if(elm.size()==size)
				return (int)sum;
			count1++;
			if(count1==10&&count2==9&&count3==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					count2=0;
				}
				count1=0;
			}
		}
		i = 10000001;
		inner = 11000;
		inner2 =100100;
		inner3=1000010;
		int inner4= 10000001;
		count1 = 0;
		count2 = 0;
		count3= 0;
		int count4=1;
		while(true) {
			int cur = count1*inner+count2*inner2+count3*inner3+count4*inner4;

			elm.add(cur);
			sum= (sum%mod+cur%mod)%mod;
		//	System.out.println(cur);
			if(elm.size()==size)
				return (int)sum;

			count1++;
			if(count1==10&&count2==9&&count3==9&&count4==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					if(count3==10) {
						count3=0;
						count4++;
					}
					count2=0;
				}
				count1=0;
			}

		}
		sum = (sum%mod+1000000001%mod)%mod;
		return sum;

	}
public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int k = sc.nextInt();
	int p = sc.nextInt();

	System.out.println(gen(p,k));

}
}

import java.io.*;
import java.util.*;

public class ProblemB {

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        boolean hasNext() {
            boolean result = false;
            try {
                result = br.ready();
            } catch (IOException e) {
                System.err.println(e);
            }
            return result;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {

        FastReader fr = new FastReader();

        int k = fr.nextInt() + 1; // k primeros zcy
        int p = fr.nextInt(); // modulo con esto

        int sum = 0;
        int pal;

        int i = 1;
        while (i < 10 && i < k) {
            pal = i * 10 + i;
            sum += pal;
            i++;
        }
        int primer;
        int segundo;
        while (i < 100 && i < k) {
            primer = i / 10; //primer y ultimo digito
            segundo = i % 10; // digitos del medio
            pal = primer * 1000 + segundo * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }
        sum %= p;
        int tercer;
        while (i < 1000 && i < k) {
            primer = i / 100;
            segundo = (i / 10) % 10;
            tercer = i % 10;
            pal = primer * 100000 + segundo * 10000 + tercer * 1000 + tercer * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }
        sum %= p;
        int cuarto;
        while (i < 10000 && i < k) {
            primer = i / 1000;
            segundo = (i / 100) % 10;
            tercer = (i / 10) % 10;
            cuarto = i % 10;
            pal = primer * 10000000 + segundo * 1000000 + tercer * 100000 + cuarto * 10000 + cuarto * 1000 + tercer * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }
        sum %= p;
        int quinto;
        while (i < 100000 && i < k) {
            primer = i / 10000;
            segundo = (i / 1000) % 10;
            tercer = (i / 100) % 10;
            cuarto = (i / 10) % 10;
            quinto = i % 10;
            pal = primer * 1000000000 + segundo * 100000000 + tercer * 10000000 + cuarto * 1000000 + quinto * 100000 + quinto * 10000 + cuarto * 1000 + tercer * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }

        System.out.println(sum % p);

    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ouheguaughwugfyuwgfiuqwgr
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static ArrayList<Long> list = new ArrayList<>();

        public void solve(int testNumber, InputReader scan, OutputWriter out) {
//        ArrayList<Long> list = new ArrayList<>();
            for (int i = 1; i <= 6; ++i) {
                generate(i - 1, "", i - 1);
//            out.println(i);
            }
            Collections.sort(list);
            out.println(list.size());
            long ans = 0;
            int k = scan.nextInt();
            long mod = scan.nextLong();
            for (int i = 0; i < k; ++i) {
                ans = (ans + list.get(i)) % mod;
//            out.println(list.get(i));
            }
            out.println(ans);
        }

        void generate(int n, String s, int length) {
//        System.out.println(n);
            if (n < 0) return;
            for (int i = 0; i <= 9; ++i) {
                String t = "";
                if (i == 0 && n == length) continue;
                t = s + Integer.toString(i);
                if (n == 0) {
                    StringBuilder sb = new StringBuilder(t);
                    sb.reverse();
                    t += sb.toString();
                    list.add(Long.parseLong(t));
                } else {
                    generate(n - 1, t, length);
                }
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	/*public static long f(long k) {
		long ans=0;
		String t=k+"";
		String nt="";
		for(int i=0;i<t.length();i++) {
			nt=t.charAt(i)+nt;
		}
		//System.out.println(nt);
		ans=Long.parseLong(t+nt);
		return ans;
	}*/
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        InputReader in = new InputReader(inputStream);
        /*
        long k=in.nextLong(), p=in.nextLong();
        long ans=0;
        for(long i=1;i<=k;i++) {
        	ans+=f(i);
        	ans%=p;
        }
        out.println(ans);*/
        out.close();
    }

    static class InputReader {

        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream), 32624);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public long[] nextArrayl(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
        public double[] nextArrayd(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextDouble();
            }
            return a;
        }

        private BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public void printAr(int[] a) {
            System.out.print("[");
            for (long x : a) {
                System.out.print(x + ",");
            }
            System.out.print("]");
        }
    }

}

import java.util.*;
public class zd{
	public static void main(String [] args){
	Scanner sc =new Scanner(System.in);int k = sc.nextInt(); int p = sc.nextInt();
	int sum = 0;
		for(int i = 1; i <= k; i++){
		sum += (i*10)+i;
		}
	System.out.print(sum%p);
	}

}

import java.util.*;
import java.text.*;
import java.io.*;
import java.math.*;
public class code5 {
	InputStream is;
	PrintWriter out;
	static long mod=pow(10,9)+7;
	static int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
	void solve() throws IOException
	{
		int n=ni();
		int p=ni();
		long sum=0;
		for(int i=1;i<=n;i++)
		{
			sum+=i;
			int num=i,len=0;
			while(num!=0)
			{
				num/=10;
				len++;
			}
			num=i;
			while(num!=00)
			{
				sum+=pow(10,len++)*(num%10);
				num/=10;
			}
		}
		out.print(sum%p);
	}
	ArrayList<Integer> al[];
 	void take(int n,int m)
 	{
 		al=new ArrayList[n];
 		for(int i=0;i<n;i++)
 			al[i]=new ArrayList<Integer>();
 		for(int i=0;i<m;i++)
 		{
 			int x=ni()-1;
 			int y=ni()-1;
 			al[x].add(y);
 			al[y].add(x);
 		}
 	}
 	int check(long n)
 	{
 		int count=0;
 		while(n!=0)
 		{
 			if(n%10!=0)
 				break;
 			n/=10;
 			count++;
 		}
 		return count;
 	}
	public static int count(int x)
	{
		int num=0;
		while(x!=0)
		{
			x=x&(x-1);
			num++;
		}
		return num;
	}
	static long d, x, y;
	void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	long modInverse(long A,long M) //A and M are coprime
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}
	public static void mergeSort(int[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(int arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		int left[] = new int[n1];
		int right[] = new int[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	public static void mergeSort(long[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(long arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		long left[] = new long[n1];
		long right[] = new long[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	 static class Pair implements Comparable<Pair>{

	       int x,y,k;
	       int i,dir;
	       long val;
		Pair (int x,int y){
			this.x=x;
			this.y=y;
		}
		public int compareTo(Pair o) {
			return this.x-o.x;
		}

		public String toString(){
			return x+" "+y+" "+k+" "+i;}
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair)o;
				return p.x == x && p.y == y;
			}
			return false;
		}
		public int hashCode() {
			return new Long(x).hashCode()*31 + new Long(y).hashCode() ;
		}
	}

	    public static boolean isPal(String s){
	        for(int i=0, j=s.length()-1;i<=j;i++,j--){
	                if(s.charAt(i)!=s.charAt(j)) return false;
	        }
	        return true;
	    }
	    public static String rev(String s){
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
	    }

	    public static long gcd(long x,long y){
		if(y==0)
			return x;
		else
			return gcd(y,x%y);
	    }

	    public static int gcd(int x,int y){
	    	if(y==0)
	    		return x;
	    	return gcd(y,x%y);
	    }

	    public static long gcdExtended(long a,long b,long[] x){

	        if(a==0){
	            x[0]=0;
	            x[1]=1;
	            return b;
	        }
	        long[] y=new long[2];
	        long gcd=gcdExtended(b%a, a, y);

	        x[0]=y[1]-(b/a)*y[0];
	        x[1]=y[0];

	        return gcd;
	    }

	    public static int abs(int a,int b){
		return (int)Math.abs(a-b);
	    }

	    public static long abs(long a,long b){
		return (long)Math.abs(a-b);
	    }

	    public static int max(int a,int b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static int min(int a,int b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long max(long a,long b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static long min(long a,long b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long pow(long n,long p,long m){
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	    }

	    public static long pow(long n,long p){
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;
	    }
	    public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
	    void run() throws Exception {
			is = System.in;
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		}

	    public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
				public void run() {
					try {
						new code5().run();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();

	    	//new code5().run();
		}
	    private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b));
			return b;
		}

		private double nd() {
			return Double.parseDouble(ns());
		}

		private char nc() {
			return (char) skip();
		}

		private String ns() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = ns(m);
			return map;
		}

		private int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = ni();
			return a;
		}
		private long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nl();
			return a;
		}

		private int ni() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc=new FastReader();
	   int sum=0;
	    int k=sc.nextInt();
	    int p=sc.nextInt();
	    for(int i=11;i<=100000;i++)
	    {
	        int dig=(int)Math.ceil(Math.log10(i));
	        int val=ispalin(i);
	       // System.out.println()
	        if(dig%2==0 && val==1){
	            k--;
	            //System.out.println(i);

	         sum=((sum%p)+(i%p))%p;
	        }
	        if(k==0)
	        break;
	    }
	    // String ans = new String(a);
	     System.out.println(sum);

	}
	static int ispalin(int n)
	{
	    int c=n;
	    int sum=0;
	    while(c>0)
	    {
	        int d=c%10;
	        sum=sum*10+d;
	        c=c/10;

	    }
	    if(n==sum)
	    return 1;
	    else
	    return 0;
	}
}
class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.util.*;
public class B897 {
public static void main(String[] args)
{
	Scanner input = new Scanner(System.in);
	int n = input.nextInt(), k = input.nextInt();
	long res = 0;
	int count = 0;
	for(int length = 2; length <= 10; length++)
	{
		int start = 1;
		for(int j = 0; j<length/2-1; j++) start *= 10;
		for(int i = start; i < start * 10; i++)
		{
			count++;
			res += reverse(i) + (i * start * 10);
			res %= k;
			if(count == n)
			{
				System.out.println(res%k);
				return;
			}
		}
	}
}
static long reverse(int x)
{
	long res = 0;
	while(x > 0)
	{
		res *= 10;
		res += x%10;
		x /= 10;
	}
	return res;
}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] arr;
        Long k,p,counter=5L,answer=0L;
        arr = in.readLine().split(" ");
        counter = Long.valueOf(arr[0]);
        p = Long.valueOf(arr[1]);
        StringBuilder helpStr = new StringBuilder();
        for (int j = 1; j < 10000; j*=10) {
            for (int i = j; i < 10*j; i++) {
                counter--;
                helpStr.append(i);
                helpStr.append((new StringBuffer(helpStr).reverse()));
                answer+=Long.valueOf(helpStr.toString());
                if (counter==0){
                    break;
                }
                helpStr.setLength(0);
            }
            if (counter==0){
                break;
            }
        }
        System.out.println(answer%p);
    }

}

import java.util.ArrayList;
import java.util.Scanner;

public class bb {
	static ArrayList<Integer> elm;
	public static long gen(int k, int p) {
	elm =new ArrayList<Integer>();
		long sum = 0;
		for(int i = 11;i<=99;i+=11) {
			elm.add(i);
			sum= (sum+i)%k;
			if(elm.size()==p)
				return (int)sum;
		}
		for(int i = 1001;i<=9999;i++) {
			String cur = i+"";
			boolean yes = true;
			for (int j = 0; j < cur.length()/2; j++) {
				if(cur.charAt(j)!=cur.charAt(cur.length()-1-j)) {
					yes = false;
					break;
				}
			}
			if(!yes)
				continue;
			elm.add(i);
			sum= (sum+i)%k;
			//System.out.println(elm.size());
			if(elm.size()==p)
				return (int)sum;

		}
		int inner = 1100;
		int inner2 =10010;
		int inner3 = 100001;
		int i = 100001;
		int count1 = 0;
		int count2 = 0;
		int count3 = 1;
		while(true) {
			int cur = count1*inner+count2*inner2+count3*inner3;
		//	System.out.println(cur);
			elm.add(cur);
			sum= (sum+cur)%k;
		//	System.out.println(elm.size());
			if(elm.size()==p)
				return (int)sum;
			count1++;
			if(count1==10&&count2==9&&count3==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					count2=0;
				}
				count1=0;
			}
		}
		i = 10000001;
		inner = 11000;
		inner2 =100100;
		inner3=1000010;
		int inner4= 10000001;
		count1 = 0;
		count2 = 0;
		count3= 0;
		int count4=1;
		while(true) {
			int cur = count1*inner+count2*inner2+count3*inner3+count4*inner4;

			elm.add(cur);
			sum= (sum+cur)%k;
		//	System.out.println(cur);
			if(elm.size()==p)
				return (int)sum;

			count1++;
			if(count1==10&&count2==9&&count3==9&&count4==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					if(count3==10) {
						count3=0;
						count4++;
					}
					count2=0;
				}
				count1=0;
			}

		}
		sum = (sum+1000000001)%p;
		return sum;

	}
public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int k = sc.nextInt();
	int p = sc.nextInt();

	System.out.println(gen(p,k));

}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc=new FastReader();
	   long sum=0;
	    int k=sc.nextInt();
	    int p=sc.nextInt();
	    for(int i=11;i<=100000;i++)
	    {
	        int dig=(int)Math.ceil(Math.log10(i));
	        int val=ispalin(i);
	       // System.out.println()
	        if(dig%2==0 && val==1){
	            k--;
	            //System.out.println(i);

	         sum=sum+(long)i;

	        }
	        if(k==0)
	        break;
	    }
	    sum=sum%p;
	    // String ans = new String(a);
	     System.out.println(sum);

	}
	static int ispalin(int n)
	{
	    int c=n;
	    int sum=0;
	    while(c>0)
	    {
	        int d=c%10;
	        sum=sum*10+d;
	        c=c/10;

	    }
	    if(n==sum)
	    return 1;
	    else
	    return 0;
	}
}
class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author khokharnikunj8
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B879 solver = new B879();
        solver.solve(1, in, out);
        out.close();
    }

    static class B879 {
        private long ans = 0;

        private void pre(int n, long p, long current, int limit) {
            if (n == 1 || n == 10 || n == 100 || n == 10000 || n == 100000) {
                current = (current * 10) % p;
            }
            ans += ((current * n) % p) + (reverse(n) % p);
            ans %= p;

            if (n + 1 <= limit) pre(n + 1, p, current, limit);
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            long p = in.scanLong();
            pre(1, p, 1, n);
            out.println(ans);

        }

        private int reverse(int n) {
            int rev = 0;
            while (n > 0) {
                rev *= 10;
                rev += (n % 10);
                n /= 10;
            }
            return rev;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.readInt();
            int p = in.readInt();
            long ans = 0, s = 1;
            for (int i = 0; i < k; i++) {
                long number = calc(s);
                ans = (ans + number) % p;
                s++;
            }
            out.println(ans);

        }

        long calc(long n) {
            long ans = n;
            int len = ("" + n).length() - 1;
            long ten = (long) Math.pow(10, len);
            while (ten > 0) {
                ans = ans * 10 + (n / ten) % 10;
                ten /= 10;
            }
            return ans;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.*;
public class Test{
    public static void main(String[] afzal){
        Scanner sc = new Scanner(System.in);
        long K = sc.nextLong();
        long P = sc.nextLong();
        String str = Long.toString(K);
        str = str+str;
        long A = Long.parseLong(str);
        for(long i=K-1;i>=1;i--){
            str = Long.toString(i);
            str = str+str;
            long B = Long.parseLong(str);
            A = A+B;
        }
        System.out.println(A%P);
    }
}

import java.util.Scanner;
public class Chtholly_request_897B
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int p = sc.nextInt();
		int sum=0;
		for(int i=1, num=0, num1;i<=k;i++)
		{
			num = i;
			num1 = num;
			while(num1>0)
			{
				num = num*10+num1%10;
				num1/=10;
			}
			sum+=num%p;
			sum%=p;
		}
		System.out.println(sum);
		sc.close();
	}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class HelloWorld {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);

		int k = in.nextInt();
		int p = in.nextInt();
		long sum = 0;
		int count = 0;
		long currentElement = 1;
		while(count < k) {
			if(currentElement % 10 == 0) {
				currentElement++;
				continue;
			}
			else {
				String number = Long.toString(currentElement);
				String newNumber = number + (new StringBuilder(number).reverse().toString());
				//System.out.println(number);
				sum = (sum + Long.parseLong(newNumber)) % p;
				currentElement++;
				count++;
			}
		}
		System.out.println(sum);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 *
 * @author antonio
 */
public class CF_449_B_ChthollysRequest {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        StringTokenizer tok = new StringTokenizer(s);
        int k = Integer.parseInt(tok.nextToken());
        int p = Integer.parseInt(tok.nextToken());
        int cont = 0;
        int i = 0;
        long sum = 0;
        ArrayList<String> nums = new ArrayList<String>(110002);
        nums.add("");
        ArrayList<String> numsN = new ArrayList<String>(110002);
        ini: while(cont < 100000){
            for (int l = 0; l < 10; l++) {
                for (String sn : nums) {
                    numsN.add(l + sn + l);
                    if(l != 0){
                        cont++;
                    }
                    if(cont == 100000){
                        break ini;
                    }
                }
            }
            nums = (ArrayList<String>) numsN.clone();
        }
        while(k > 0){
            if(numsN.get(i).charAt(0) != '0'){
                sum += Long.parseLong(numsN.get(i));
                sum %= p;
                k--;
            }
            i++;
        }
        System.out.println(sum);
    }
}

//package B;
/**
 * Created by Eesaa on 12/5/2017.
 */

import java.util.*;

public class B_897 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), p = in.nextInt();
        System.out.println(sumOfNumbers(n)%p);
        in.close();
    }

    static long sumOfNumbers (int n){
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            long num = Long.parseLong(i+""+i);
            sum+=num;
        }
        return sum;
    }
}

import java.util.Scanner;

public class B_Chthollys_Request {

    public static void main(String[] args) {

        Scanner entrada = new Scanner(System.in);

        int k = entrada.nextInt(), p = entrada.nextInt(), contador = 0;
        boolean par = true, impar = false, acabo = false;
        long acumuladorFinal = 0;
        byte e = 0;
        String aux, aux2;

        while (contador != k) {

            if (par) {
                for (int i = (int) Math.pow(10, e); i <= 9 * Math.pow(10, e); i++) {
                    aux = String.valueOf(i);
                    aux2 = aux;
                    for (int j = aux.length() - 1; j >= 0; j--) {
                        aux2 += aux.substring(j, j + 1);
                    }
                    acumuladorFinal += Integer.parseInt(aux2);
                    contador++;
                    if (contador == k) {
                        acabo = true;
                        break;
                    }
                }
                par = false;
                impar = true;
            }

            if (acabo == true) {
                break;
            }

            if (impar) {
                e++;

                for (int i = (int) Math.pow(10, e); i <= 9 * Math.pow(10, e); i++) {
                    aux = String.valueOf(i);
                    aux2 = aux;
                    for (int j = aux.length() - 2; j >= 0; j--) {
                        aux2 += aux.substring(j, j + 1);
                    }
                    acumuladorFinal += Integer.parseInt(aux2);
                    contador++;
                    if (contador == k) {
                        acabo = true;
                        break;
                    }
                }
                par = true;
                impar = false;
            }
        }
        System.out.println(acumuladorFinal % p);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        int[] pow = new int[12];

        public void solve(int testNumber, InputReader in, FastWriter out) {
            int k = in.nextInt();
            int mod = in.nextInt();

            pow[0] = 1;
            for (int i = 1; i < pow.length; ++i)
                pow[i] = NumberTheory.multiply(pow[i - 1], 10, mod);

//        long start = 1, end = start * 10;
//        int j = 1;
//        int res = 0;
//        while (k > 0) {
//            for (long i = start; i < end && k > 0; i++, k--) {
//                res = add(res, multiply((int)(i%mod), pow[j], mod), mod);
//                long ii = i;
//                int r = j - 1;
//                while (ii != 0) {
//                    res = add(res, multiply((int) ii % 10, pow[r], mod), mod);
//                    r--;
//                    ii /= 10;
//                }
//                start *= 10;
//                end *= 10;
//            }
//            j++;
//        }
//
//        out.println(res);

            int[] kk = {k};
            int res = 0;
            int n = 1;
            do {
                int[] a = new int[n];
                res += NumberTheory.add(res, compute(0, a, n, kk, mod));
                n++;
            } while (kk[0] > 0);
            out.println(res);
        }

        private int compute(int pos, int[] a, int n, int[] k, int mod) {
            if (k[0] <= 0) return 0;

            if (pos == n) {
                int res = 0;
                for (int i = n - 1; i >= 0; i--) {
                    int temp = NumberTheory.multiply(a[i], NumberTheory.add(pow[i], pow[2 * n - i - 1], mod), mod);
                    res = NumberTheory.add(res, temp, mod);
                }
                k[0]--;
                return res;
            }
            int res = 0;
            for (int digit = (pos == 0) ? 1 : 0; digit < 10 && k[0] > 0; ++digit) {
                a[pos] = digit;
                res = NumberTheory.add(res, compute(pos + 1, a, n, k, mod), mod);
            }
            return res;
        }

    }

    static class NumberTheory {
        public static final int MODULO = 1_000_000_007;

        public static int multiply(int a, int b, int mod) {
            long product = a * (long) b;
            if (product >= mod)
                product %= mod;
            return (int) product;
        }

        public static int add(int a, int b) {
            long sum = a + (long) b;
            if (sum >= MODULO)
                sum -= MODULO;
            return (int) sum;
        }

        public static int add(int a, int b, int mod) {
            long sum = a + (long) b;
            if (sum >= mod)
                sum %= mod;
            return (int) sum;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }

    static class FastWriter extends PrintWriter {
        public FastWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public FastWriter(Writer writer) {
            super(writer);
        }

        public FastWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

    }
}

import java.io.*;
import java.util.*;

public class Solution {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong(), p = scanner.nextLong(), result = 0, cur = 0;
		for (int i = 0, j = 1; i < n; i++) {
		    String st = String.valueOf(j);
		    StringBuilder stb = new StringBuilder();
		    stb.append(st);
		    stb.reverse();
		    st += stb;
		    cur = Long.parseLong(st);
		    cur %= p;
		    result += cur;
		    result %= p;
		    j++;
		    st = String.valueOf(j);
		    for (int k = st.length() - 1; k >= 0; k--) {
		        if (st.charAt(k) == '0') {
		            j += Math.pow(10, st.length() - k - 1);
		        }
		    }
		}
		System.out.printf("%d", result);
	}
}

import java.util.Scanner;

public class B_Chthollys_Request {

    public static void main(String[] args) {

        Scanner entrada = new Scanner(System.in);

        int k = entrada.nextInt(), p = entrada.nextInt(), contador = 0;
        boolean par = true, impar = false, acabo = false;
        long acumuladorFinal = 0;
        int e = 0;
        String aux, aux2;

        while (contador != k) {

            if (par) {
                for (int i = (int) Math.pow(10, e); i <= Math.pow(10, e + 1) - 1; i++) {
                    aux = String.valueOf(i);
                    aux2 = aux;
                    for (int j = aux.length() - 1; j >= 0; j--) {
                        aux2 += aux.substring(j, j + 1);
                    }
                    acumuladorFinal += Integer.parseInt(aux2);
                    contador++;
                    if (contador == k) {
                        acabo = true;
                        break;
                    }
                }
                par = false;
                impar = true;
            }

            if (acabo == true) {
                break;
            }

            if (impar) {
                e++;

                for (int i = (int) Math.pow(10, e); i <= Math.pow(10, e + 1) - 1; i++) {
                    aux = String.valueOf(i);
                    aux2 = aux;
                    for (int j = aux.length() - 2; j >= 0; j--) {
                        aux2 += aux.substring(j, j + 1);
                    }
                    acumuladorFinal += Integer.parseInt(aux2);
                    contador++;
                    if (contador == k) {
                        acabo = true;
                        break;
                    }
                }
                par = true;
                impar = false;
            }
        }
        System.out.println(acumuladorFinal % p);
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package codeforces;

import java.util.Scanner;
//import java.util.*;
/**
 *
 * @author StefanusKB
 */
public class CodeForces {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan = new Scanner(System.in);
        String result = "";
        int k = scan.nextInt();
        int p = scan.nextInt();
        int sumPalin = 0;
        int counterK = 0;
        int counterInt = 1;
        while(counterK<k){
            int palin = 11*counterInt++;
            String checkDigits = palin+"";
            if(checkDigits.length()%2==0){
                sumPalin+=palin;
                counterK++;
            }
        }
        result = (sumPalin%p)+"";
        System.out.println(result);//print end result
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.KeyStore.Entry;
import java.time.temporal.JulianFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.JLabel;

public class answertillD {
	static int minn;

	static class pair implements Comparable<pair> {
		int u;
		int v;

		public pair(int uo, int vo) {
			u = uo;
			v = vo;

		}

		@Override
		public String toString() {
			return "pair [u=" + u + ", v=" + v + "]";
		}

		@Override
		public int compareTo(pair e) {
			if (u == e.u && v == e.v)
				return 0;
			if (u > e.u || e.u > u)
				return u - e.u;
			else
				return 1;
		}
	}

	static class edge implements Comparable<edge> {
		int u;
		int v;
		int w;

		@Override
		public String toString() {
			return "edge [u=" + u + ", v=" + v + ", w=" + w + "]";
		}

		public edge(int uo, int vo, int wo) {
			u = uo;
			v = vo;
			w = wo;
		}

		@Override
		public int compareTo(edge e) {
			// TODO Auto-generated method stub
			return w - e.w;
		}
	}

	public static long power(long x, long y) {
		long ans = 1;
		while (y-- > 0) {
			if (ans <= 1e18 / x)
				ans *= x;
			else {
				ans = Long.MAX_VALUE;
				break;
			}
		}
		return ans;
	}

	public static char[][] reb() {
		int n = smallArr.length;
		char[][] arr = new char[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				arr[i][j] = smallArr[n - j - 1][i];

		return arr;
	}

	static int[] Arr, cost, level;
	static char[][] smallArr;
	static boolean[][] memo;
	static int n;
	static long S;
	static final int VISITED = 2, EXPLORED = 1, UNVISITED = 0;
	static ArrayList<Integer>[] adjList;
	static boolean[] visited, adjMat[];
	static int V, E;

	static long bfs(String str, int k) {
		Queue<String> q = new LinkedList<String>();
		q.add(str);
		HashSet<String> hs = new HashSet<String>();
		hs.add(str);
		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		hm.put(str, 0);
		long ans = 0;
		while (k > 0 && !q.isEmpty()) {
			String u = q.remove();
			for (int v = 0; v < u.length(); v++) {
				String sam = u.substring(0, v) + u.substring(v + 1);
				if (!hm.containsKey(sam)) {
					int x = hm.get(u) + 1;
					hm.put(sam, x);
					k--;
					ans += x;
					if (k == 0)
						break;
					q.add(sam);
				}
			}

		}
		if (k != 0)
			return -1;
		return ans;

	}

	public static long GCD(long a, long b) {
		if (b == 0)
			return a;
		return GCD(b, a % b);
	}

	public static long powerlog(long x, long y, int mod) {
		long res = 1; // Initialize result
		while (y > 0) {
			if ((y & 1) == 1)
				res = (res * x);
			// res %= mod;
			y = y >> 1; // y = y/2
			x = (x * x);
			// x %= mod;
		}
		return res;
	}

	public static String rev(String str) {
		StringBuilder sb = new StringBuilder();
		for (int i = str.length() - 1; i >= 0; i--) {
			sb.append(str.charAt(i));
		}
		return sb + "";
	}

	public static boolean checj(int numa, int b, int a, int n, int k) {
		int numb = n - numa;
		if (k % a == 0) {
			if (k / a - 1 < numa)
				return false;
		} else {
			if (k / a < numa)
				return false;
		}
		k -= numa * a;
		if (k % b == 0) {
			if (k / b - 1 < numb)
				return false;
		} else {
			if (k / b < numb)
				return false;
		}
		return true;
	}

	static int mod;
	static String ans;
	static int[] arr;

	public static boolean dp(int idx, int rem) {
		if (idx == n)
			return rem % mod == 0;

		if (!memo[idx][rem])
			return memo[idx][rem];
		if (cost[idx] != -1) {
			arr[idx] = cost[idx];
			return memo[idx][rem] = dp(idx + 1, (int) ((rem + cost[idx] * powerlog(10, n - 1 - idx, mod)) % mod));

		}
		boolean flag = false;
		for (int i = 0; i < 10; i++) {
			if (idx == 0 && i == 0)
				continue;
			arr[idx] = i;
			flag = dp(idx + 1, (int) ((rem + i * powerlog(10, n - idx - 1, mod)) % mod));
			if (flag)
				break;
		}

		return memo[idx][rem] = flag;
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int p = sc.nextInt();
		long ans = 0;
		long sum = 0;
		int shift1 = 0;
		int shift2 = 0;
		int shift3 = 0;
		int shift4 = 0;
		int shift5 = 0;
		outer: for (int i = 0; i < 10; i++) {
			if (i == 1)
				shift1++;
			long r = powerlog(10, 0, p) * i + powerlog(10, 11, p) * i;
			sum += r;
			// sum%=p;
			for (int j = 0; j < 10; j++) {
				if (j == 1&&i==0)
					shift2++;
				int sumssss = shift1;
				long q = powerlog(10, 0 + sumssss, p) * j + powerlog(10, 9 + sumssss, p) * j;
				sum += q;
				// sum%=p;
				for (int k = 0; k < 10; k++) {
					if (k == 1&&j==0)
						shift3++;
					int sumsss = shift1 + shift2;
					long o = powerlog(10, 0 + sumsss, p) * k + powerlog(10, 7 + sumsss, p) * k;
					sum += o;
					// sum%=p;
					for (int l = 0; l < 10; l++) {
						if (l == 1&&k==0)
							shift4++;
						int sumss = shift1 + shift2 + shift3;
						long z = powerlog(10, 0 + sumss, p) * l + powerlog(10, 5 + sumss, p) * l;
						sum += z;
						// sum%=p;
						for (int m = 0; m < 10; m++) {
							if (m == 1&&l==0)
								shift5++;
							int sums = shift1 + shift2 + shift3 + shift4;
							long y = powerlog(10,  sums, p) * m + powerlog(10, 3 + sums, p) * m;
							sum += y;
							// sum%=p;
							for (int u = 0; u < 10; u++) {
								int sumsh = shift1 + shift2 + shift3 + shift4 + shift5;
								long x = powerlog(10, sumsh, p) * u + powerlog(10, 1 + sumsh, p) * u;
								sum += x;
							//	System.out.println(sumsh+" "+sum);

								ans += (sum % p);
								sum -= x;
								ans %= p;
								if (sumsh == 0 && u == 0)
									continue;
								n--;
								if (n == 0)
									break outer;

							}
							sum -= y;
						}
						sum -= z;
					}
					sum -= o;
				}
				sum -= q;
			}
			sum -= r;
		}
		pw.print(ans);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}

import java.util.Scanner;

public class ZCY {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int k,p;
		k = sc.nextInt();
		p = sc.nextInt();
		int x;
		int sum=0;
		int i=1;
		while(i<=k)
		{
			x = 11 * i;
			String y = Integer.toString(x);
			if((y.length()%2)==1)
			{
				i++;
				continue;
			}
			else
			{
				sum+=x;
				i++;
			}

		}
		System.out.println((sum%p));

	}

}

import java.util.Scanner;

public class Eieve {

    public static void main(String args[]) {

        Scanner input = new Scanner(System.in);

        long k = input.nextInt(), p = input.nextInt(), j = 11, i1 = 0, sum = 0;

        for (int i = 1; i <= k; i++) {
            i1 = i * 10 + i % 10;
            sum = sum + i1;
        }
        System.out.println(sum % p);

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] arr;
        Long k,p,counter=5L,answer=0L;
        arr = in.readLine().split(" ");
        counter = Long.valueOf(arr[0]);
        p = Long.valueOf(arr[1]);
        StringBuilder helpStr = new StringBuilder();
        for (int j = 1; j < 100000; j*=10) {
            for (int i = j; i < 10*j; i++) {
                counter--;
                helpStr.append(i);
                helpStr.append((new StringBuffer(helpStr).reverse()));
                answer+=Long.valueOf(helpStr.toString());
                if (counter==0){
                    break;
                }
                helpStr.setLength(0);
            }
            if (counter==0){
                break;
            }
        }
        System.out.println(answer%p);
        //System.out.println(counter);
    }

}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc=new FastReader();
	   long sum=0;
	    int k=sc.nextInt();
	    long p=sc.nextLong();
	    for(int i=1;i<=k;i++)
	    {
	       //
	       // int val=ispalin(i);
	       // System.out.println()
	       // if(dig%2==0 && val==1){
	           // k--;

	        long x = 11 * i;
	        int dig=(int)Math.ceil(Math.log10(x));
	        //System.out.println(dig+);
	        if(dig%2==0 && ispalin(x)==1)
	         sum = ((sum%p)+(x%p))%p;
	         //System.out.println(i+"    "+sum+"    "+k);
	         //sum = sum + x;

	    }
	    //sum=sum%p;
	    // String ans = new String(a);
	     System.out.println(sum);

	}
	static int ispalin(long n)
	{
	    long c=n;
	    long sum=0;
	    while(c>0)
	    {
	        long d=c%10;
	        sum=sum*10+d;
	        c=c/10;

	    }
	    if(n==sum)
	    return 1;
	    else
	    return 0;
	}

}
class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc=new FastReader();
	   long sum=0;
	    int k=sc.nextInt();
	    long p=sc.nextLong();
	    for(int i=1;i<=k;i++)
	    {
	       //
	       // int val=ispalin(i);
	       // System.out.println()
	       // if(dig%2==0 && val==1){
	           // k--;

	        long x = 11 * i;
	        int dig=(int)Math.ceil(Math.log10(x));
	        if(dig%2==0)
	         sum = ((sum%p)+(x%p))%p;
	         //System.out.println(i+"    "+sum+"    "+k);
	         //sum = sum + x;

	    }
	    //sum=sum%p;
	    // String ans = new String(a);
	     System.out.println(sum);

	}

}
class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc=new FastReader();
	   long sum=0;
	    int k=sc.nextInt();
	    long p=sc.nextLong();

	       for(int i=1;i<=k;i++)
	       {
	        long x = (long)i;
	        int dig=(int)Math.ceil(Math.log10(x));
	        long y=ispalin(x);
	        if(dig==0)
	        dig=1;
	        if(x==10)
	        dig=2;
	        x= (long)(x*Math.pow(10,dig))+y;
	       // System.out.println(x+" "+y+" "+dig);
	        //System.out.println(dig+);
	        //if(dig%2==0 && ispalin(x)==1){
	         sum = ((sum%p)+(x%p))%p;

	        }

	     System.out.println(sum);

	}
	static long ispalin(long n)
	{
	    long c=n;
	    long sum=0;
	    while(c>0)
	    {
	        long d=c%10;
	        sum=sum*10+d;
	        c=c/10;

	    }
	    return sum;
	}

}
class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.io.*;
import java.util.*;

public class ProblemB {

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        boolean hasNext() {
            boolean result = false;
            try {
                result = br.ready();
            } catch (IOException e) {
                System.err.println(e);
            }
            return result;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {

        FastReader fr = new FastReader();

        int k = fr.nextInt() + 1; // k primeros zcy
        int p = fr.nextInt(); // modulo con esto

        int sum = 0;
        int pal;

        int i = 1;
        while (i < 10 && i < k) {
            pal = i * 10 + i;
            sum += pal;
            i++;
        }
        int primer;
        int segundo;
        while (i < 100 && i < k) {
            primer = i / 10; //primer y ultimo digito
            segundo = i % 10; // digitos del medio
            pal = primer * 1000 + segundo * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }
        int tercer;
        while (i < 1000 && i < k) {
            primer = i / 100;
            segundo = (i / 10) % 10;
            tercer = i % 10;
            pal = primer * 100000 + segundo * 10000 + tercer * 1000 + tercer * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }
        int cuarto;
        while (i < 10000 && i < k) {
            primer = i / 1000;
            segundo = (i / 100) % 10;
            tercer = (i / 10) % 10;
            cuarto = i % 10;
            pal = primer * 10000000 + segundo * 1000000 + tercer * 100000 + cuarto * 10000 + cuarto * 1000 + tercer * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }
        int quinto;
        while (i < 100000 && i < k) {
            primer = i / 10000;
            segundo = (i / 1000) % 10;
            tercer = (i / 100) % 10;
            cuarto = (i / 10) % 10;
            quinto = i % 10;
            pal = primer * 1000000000 + segundo * 100000000 + tercer * 10000000 + cuarto * 1000000 + quinto * 100000 + quinto * 10000 + cuarto * 1000 + tercer * 100 + segundo * 10 + primer;
            sum += pal;
            i++;
        }

        System.out.println(sum % p);

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class CFB {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;

    void solve() throws IOException {
        int k = nextInt();
        int p = nextInt();
        long cur = System.currentTimeMillis();
        long res = 0;
        PriorityQueue<Long> pq = new PriorityQueue<>();
        for (int i = 1; i < 10; i++) {
            pq.add((long) 10 * i + i);
        }

        for (int i = 0; i < k; i++) {
            long nxt = pq.poll();
            res += nxt;
            res %= p;
            String all = Long.toString(nxt);
            String first = all.substring(0, all.length() / 2);
            for (int j = 0; j < 10; j++) {
                String cand = first + j + j + first;
                long fur = Long.parseLong(cand);
                pq.add(fur);
            }
        }

        long cur2 = System.currentTimeMillis();
        out(res);
    }

    void shuffle(long[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            long tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFB() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFB();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

import java.util.*;
public class zd{
	public static void main(String [] args){
	Scanner sc =new Scanner(System.in);int k = sc.nextInt(); int p = sc.nextInt();
	int sum = 0;
	for(int i = 1; i <= k; i++){
		int icopy = i;
		while(icopy>0){
			sum += (i*10)+(i%10);
			icopy /=10;
		}
	}
	System.out.print(sum%p);
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author khokharnikunj8
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B879 solver = new B879();
        solver.solve(1, in, out);
        out.close();
    }

    static class B879 {
        private long ans = 0;
        private int total = 0;

        private void pre(int n, int p, long current, long check) {
            if (total >= n) return;
            LinkedList<Long> ln = new LinkedList<>();
            long temp;
            if (total == 0) ln.add(0l);
            for (int i = 0; i < 10 && total < n; i++) {
                temp = current;
                temp = (temp * 10) % p;
                temp += ((check * i) % p);
                temp += i;
                if (!(temp == 0 && total == 0 && i == 0)) total++;
                if (total != 0 && temp != 0) ln.add(temp);
                ans = (ans + temp) % p;
            }

            for (int i = 0; i < ln.size() && total < n; i++) {
                pre(n, p, ln.get(i), (check * 100) % p);
            }

        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int p = in.scanInt();
            pre(n, p, 0, 10);
            out.println(ans);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

	/*	/ ﾌﾌ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム
		/ )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀  Y
		(⠀⠀| ( ͡° ͜ʖ ͡°）⠀⌒(⠀ ノ
		(⠀ ﾉ⌒ Y ⌒ヽ-く __／
		| _⠀｡ノ| ノ｡ |/
		(⠀ー '_人`ー ﾉ
		⠀|\ ￣ _人'彡ﾉ
		⠀ )\⠀⠀ ｡⠀⠀ /
		⠀⠀(\⠀ #⠀ /
		⠀/⠀⠀⠀/ὣ====================D-
		/⠀⠀⠀/⠀ \ \⠀⠀\
		( (⠀)⠀⠀⠀⠀ ) ).⠀)
		(⠀⠀)⠀⠀⠀⠀⠀( | /
		|⠀ /⠀⠀⠀⠀⠀⠀ | /
		[_] ⠀⠀⠀⠀⠀[___]                     */
	// Main Code at the Bottom
	import java.util.*;
	import java.lang.*;
	import java.io.*;
	import java.math.BigInteger;
	public class Main {
		//Fast IO class
	    static class FastReader {
	        BufferedReader br;
	        StringTokenizer st;
	        public FastReader() {
	        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
	        	if(!env) {
	        		try {
						br=new BufferedReader(new FileReader("src\\input.txt"));
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
	        	}
	        	else br = new BufferedReader(new InputStreamReader(System.in));
	        }
	        String next() {
	            while (st == null || !st.hasMoreElements()) {
	                try {
	                    st = new StringTokenizer(br.readLine());
	                }
	                catch (IOException  e) {
	                    e.printStackTrace();
	                }
	            }
	            return st.nextToken();
	        }
	        int nextInt() {
	            return Integer.parseInt(next());
	        }
	        long nextLong() {
	            return Long.parseLong(next());
	        }
	        double nextDouble() {
	            return Double.parseDouble(next());
	        }
	        String nextLine() {
	            String str = "";
	            try {
	                str = br.readLine();
	            }
	            catch (IOException e) {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	    static long MOD=1000000000+7;
	    //Euclidean Algorithm
	    static long gcd(long A,long B){
	    	return (B==0)?A:gcd(B,A%B);
	    }
	    //Modular Exponentiation
	    static long fastExpo(long x,long n){
	        if(n==0) return 1;
	        if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
	        return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
	    }
	    //Modular Inverse
	    static long inverse(long x) {
	    	return fastExpo(x,MOD-2);
	    }
	    //Prime Number Algorithm
	    static boolean isPrime(long n){
	        if(n<=1) return false;
	        if(n<=3) return true;
	        if(n%2==0 || n%3==0) return false;
	        for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;
	        return true;
	    }
	    //Reverse an array
	    static void reverse(char arr[],int l,int r){
	    	while(l<r) {
	    		char tmp=arr[l];
	    		arr[l++]=arr[r];
	    		arr[r--]=tmp;
	    	}
	    }
	    //Print array
	    static void print1d(int arr[]) {
	    	out.println(Arrays.toString(arr));
	    }
	    static void print2d(int arr[][]) {
	    	for(int a[]: arr) out.println(Arrays.toString(a));
	    }
	    // Pair
	    static class pair{
	    	int x,y;
	    	pair(int a,int b){
	    		this.x=a;
	    		this.y=b;
	    	}
	    	public boolean equals(Object obj) {
	    		if(obj == null || obj.getClass()!= this.getClass()) return false;
	            pair p = (pair) obj;
	            return (this.x==p.x && this.y==p.y);
	        }
	    	public int hashCode() {
	            return Objects.hash(x,y);
	        }
	    }
	    static FastReader sc=new FastReader();
	    static PrintWriter out=new PrintWriter(System.out);
	    //Main function(The main code starts from here
	    public static void main (String[] args) throws java.lang.Exception {
	    	int test=1;
	    	//test=sc.nextInt();
	    	while(test-->0){
	    		int n=sc.nextInt();
	    		long p=sc.nextLong(),sum=0;
	    		for(int i=1;i<=n;i++) {
	    			sum=(sum%p+(11*i)%p)%p;
	    		}
	    		out.println(sum);
	    	}
	        out.flush();
	        out.close();
	    }
	}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            int k = sc.nextInt();
            int p = sc.nextInt();
            long sum = 0, f = 0;
            for (int i = 0; i < k; i++) {
                f += 11;
                String s = String.valueOf(f);
                if (s.length() % 2 == 0) {
                    sum += f;
                }
            }
            System.out.println(sum % p);

    }
}

import java.io.*;
import java.util.*;

public class Main {
    static long sum (long a[]) {
        long res = 0;
        int n = a.length;
        for (int i = 0; i < n; i++) res += a[i];
        return res;
    }

    static void solve() throws IOException {
        rl();
        int k = ni2(), p = ni2();
        long res = 0;
        boolean stop = false;
        if (k > 0) {
            for (int i = 1; i <= 9; i++) {
                long add = 11 * i;
                res += add;
                k --;
                if (k <= 0) break;
            }
            res %= p;
        }
        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    long add = i1 * 1001 + i2 * 110;
                    res += add;
                    k--;
                    if (k <= 0){
                        stop = true;
                        break;
                    }
                }
                if (stop) break;
            }
        }
        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    for (int i3 = 0; i3 <= 9; i3++) {
                        long add = i1 * 100001 + i2 * 10010 + i3 * 1100;
                        res += add;
                        k--;
                        if (k <= 0){
                            stop = true;
                            break;
                        }
                    }
                    res %= p;
                    if (stop) break;
                }
                if (stop) break;
            }
        }
        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    for (int i3 = 0; i3 <= 9; i3++) {
                        for (int i4 = 0; i4 <= 9; i4++) {
                            res += i1 * 10000001 + i2 * 1000010 + i3 * 100100 + i4 * 11000;
                            k--;
                            if (k <= 0){
                                stop = true;
                                break;
                            }
                        }
                        res %= p;
                        if (stop) break;
                    }
                    if (stop) break;
                }
                if (stop) break;
            }
        }

        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    for (int i3 = 0; i3 <= 9; i3++) {
                        for (int i4 = 0; i4 <= 9; i4++) {
                            for (int i5 = 0; i5 <= 9; i5++) {
                                res += i1 * 1000000001 + i2 * 100000010 + i3 * 10000100 + i4 * 1001000 + i5 * 110000;
                                res %= p;
                                k--;
                                if (k <= 0){
                                    stop = true;
                                    break;
                                }
                            }
                            if (stop) break;
                        }
                    }
                    if (stop) break;
                }
                if (stop) break;
            }
        }

        res %= p;

        ans.append(res);
        output.write(ans.toString());
        output.flush();
        output.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
    static StringBuilder ans = new StringBuilder();
    static String line;
    static StringTokenizer stringTokenizer;

    static int ni1() throws IOException {
        return Integer.parseInt(input.readLine());
    }

    static int ni2() throws IOException {
        return Integer.parseInt(stringTokenizer.nextToken());
    }

    static long nl1() throws IOException {
        return Long.parseLong(input.readLine());
    }

    static long nl2() {
        return Long.parseLong(stringTokenizer.nextToken());
    }

    static void rl() throws IOException {
        stringTokenizer = new StringTokenizer(input.readLine());
    }
}

import java.util.Scanner;

public class B449 {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int k = input.nextInt();
		int p = input.nextInt();
		int sum = 0;
		for (int i = 1; i <=k; i++){
			sum += palindrome(i);
			sum %= p;
		}
		System.out.println(sum);
	}

	public static int palindrome(int n){
		int c = n;
		while(c > 0){
			n *= 10;
			n += c % 10;
			c /= 10;
		}
		return n;
	}

}

import java.util.ArrayList;
import java.util.Scanner;

public class palindrome {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		long b = scan.nextLong();
		int sum = 0;
		long s3 = 0;
		boolean pali = false;
		ArrayList<Long> arr = new ArrayList<Long>();
		for(int i =1;i<a+1;i++){
			String s = Integer.toString(i);
			String s1 = "";
			String s2 = "";
			for(int j =0;j<s.length();j++){
				s1 = s1+s.charAt(j);
			}
			for(int j =s.length();j>0;j--){
				s2 = s2+s.charAt(j-1);
			}
			s = s1+s2;
//			System.out.println(s1+" "+s2);
//			if(s.length()>1 && s.length()%2 == 0)if(s1.equals(s2)){
//				pali = true;
//				arr.add(i);
//			}
//			if(arr.size()==a){
//				break;
//			}
			if(s.length()>1 && s.length()%2 == 0)
			s3 = Long.parseLong(s);
			arr.add(s3);
			if(arr.size()== a)break;
		}
		for(int i =0;i<arr.size();i++){
			sum+=arr.get(i);
		}
		System.out.println(sum%b);

	}

}

import java.util.Scanner;

public class B449 {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int k = input.nextInt();
		int p = input.nextInt();
		int sum = 0;
		for (int i = 1; i <=k; i++){
			sum += palindrome(i) % p;
			sum %= p;
		}
		System.out.println(sum);
	}

	public static int palindrome(int n){
		int c = n;
		while(c > 0){
			n *= 10;
			n += c % 10;
			c /= 10;
		}
		return n;
	}

}

import java.util.Scanner;

public class App {

	public static int rev(int n, int p) {
		int num = n;
		int ct = 0, rev = 0;
		while(num != 0) {
			rev = rev * 10 + (num % 10);
			ct++;
			num = num / 10;
		}
		num = n * (int)Math.pow(10, ct) + rev;
		return num % p;
	}

	public static void main(String[] args) {
		Scanner inp = new Scanner(System.in);
		int k = inp.nextInt();
		int p = inp.nextInt();
		int n = 0, res = 0;
		for (int i = 0; i < k; i++) {
			n++;
			res = (res + rev(n, p)) % p;
		}
		System.out.println(res);
		inp.close();
	}

}

import java.math.BigInteger;
import java.util.*;
public class duh {
     public static void main(String[] args) {
        Scanner ob=new Scanner(System.in);
        int k=ob.nextInt();
        int p=ob.nextInt();
        long sum=0;
        for(int i=1;i<=k;i++)
        {
            StringBuilder sb=new StringBuilder(i);
            long ans=Long.parseLong(""+i+(""+sb.reverse()));
            sum=(sum+ans)%p;
        }
        System.out.println(sum%p);
    }
    }

import java.util.Arrays;
import java.util.Scanner;

public class B_449 {

	public static String getnum(int num) {
		String s = Integer.toString(num);
		int i = s.length()-1;
		StringBuilder sb = new StringBuilder();
		for(int j = i; j >= 0 ; j--) {
			sb.append(s.charAt(j));
		}
		StringBuilder rev = new StringBuilder();
		for(int k = 0; k <= i; k++) {
			rev.append(s.charAt(k));
		}

		return rev.toString()+sb.toString();
	}

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int k = scn.nextInt();
		int p = scn.nextInt();

		long res = 0;
		for(int i = 1; i < 1000; i++) {
			if(k == 0) break;
//			System.out.println(i+" ** ");
			long n = Long.parseLong(getnum(i));
//			System.out.println(n+" -- ");
			res += n;
			res %= p;
			k--;
		}
		System.out.println(res);

	}

}

import java.io.*;
import java.util.*;

public class Solution{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int P = sc.nextInt();

    System.out.println(compute(K, P));
  }

  public static int compute(int K, int P){
    char[] num = {'1', '1'};
    int total = 0;
    while(K > 0){
      int i = num.length / 2 - 1;
      int j = num.length / 2;

      long curr = Long.parseLong(new String(num));
      total = (total + (int)(curr % P)) % P;
      System.out.println("Test: " + curr);
      // System.out.println(P);
      // System.out.println(total);
      K--;

      while(i >= 0 && j < num.length && num[i] == '9' && num[j] == '9'){
        num[i--] = '0';
        num[j++] = '0';
      }

      // All digits are 9's
      if(i < 0 || j >= num.length){
        char[] temp = new char[num.length + 2];
        temp[0] = '1';
        temp[num.length+1] = '1';

        for(int k = 1; k < num.length+1; k++){
          temp[k] = '0';
        }

        num = temp;

      } else {

        // find next zcy number
        num[i]++;
        num[j]++;
      }
    }

    return total;

  }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ahmed Ayman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static ArrayList<Long> a = new ArrayList<>();
        static int mod;

        static void generate(int size, StringBuilder sb, boolean start) {
            if (size == 0) {
                sb.append(sb.reverse());
                a.add(Long.parseLong(sb.toString()) % mod);
                return;
            }
            if (start) {
                for (int i = 1; i <= 9; i++) {
                    StringBuilder tmp = new StringBuilder();
                    tmp.append(sb.toString());
                    tmp.append(i);
                    generate(size - 2, tmp, false);
                }
            } else {
                for (int i = 0; i <= 9; i++) {
                    StringBuilder tmp = new StringBuilder();
                    tmp.append(sb.toString());
                    tmp.append(i);
                    generate(size - 2, tmp, false);
                }
            }
        }

        static void generate() {
            int size = 2;
            while (a.size() <= 100000) {
                generate(size, new StringBuilder(), true);
                size += 2;
            }
            return;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int k = in.nextInt();
            mod = in.nextInt();
            long sum = 0;
            generate();
            for (int i = 0; i < k; i++) {
//            out.println(a.get(i));
                sum = (sum + a.get(i)) % mod;
            }
            out.println(sum);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st = new StringTokenizer("");

    public static void main(String[] args) {
        int k = ni();
        int p = ni();
        long sum = 0;
        for (int i = 1; i <= k; i++) {
            StringBuilder sb = new StringBuilder(Long.toString(i));
            sum = (sum + Long.parseLong(sb.append(sb.reverse()).toString()) % p);
        }
        System.out.println(sum);
    }

    private static String ns() {
        while (!st.hasMoreTokens()) try {
            st = new StringTokenizer(br.readLine());
        } catch (IOException ignored) {
        }
        return st.nextToken();
    }

    private static int ni() {
        return Integer.parseInt(ns());
    }

    private static long nl() {
        return Long.parseLong(ns());
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class HelloWorld {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);

		int k = in.nextInt();
		int p = in.nextInt();
		long sum = 0;
		int count = 0;
		long currentElement = 1;
		while(count < k) {
			if(currentElement % 10 == 0) {
				currentElement++;
				continue;
			}
			else {
				String number = Long.toString(currentElement);
				String newNumber = number + (new StringBuilder(number).reverse().toString());
				//System.out.println(number);
				sum = (sum + Long.parseLong(newNumber)) % p;
				currentElement++;
				count++;
			}
		}
		System.out.println(sum);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ouheguaughwugfyuwgfiuqwgr
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader scan, OutputWriter out) {
            TreeSet<Integer> list = new TreeSet<>();
            for (int i = 2; i <= 6; i += 2) {
                if (i == 2) {
                    String s = "";
                    for (int k = 1; k <= 9; ++k) {
                        s = "";
                        s += Integer.toString(k);
                        StringBuffer sb = new StringBuffer(s);
                        sb = sb.reverse();
                        s += sb.toString();
                        list.add(Integer.parseInt(s));
                    }
                }
                if (i == 4) {
                    String s = "";
                    for (int k = 1; k <= 9; ++k) {
                        s = "";
                        s += Integer.toString(k);
                        String t = "";

                        for (int l = 0; l <= 9; l++) {
                            t = "";
                            t = s + Integer.toString(l);
                            StringBuffer sb = new StringBuffer(t);
                            sb = sb.reverse();
                            t += sb.toString();
                            list.add(Integer.parseInt(t));
                        }
                    }
                }
                if (i == 6) {
                    String s = "";
                    for (int k = 1; k <= 9; ++k) {
                        s = "";
                        s += Integer.toString(k);
                        String t = "";
                        for (int l = 0; l <= 9; l++) {
                            t = "";
                            t = s + Integer.toString(l);
                            String r = "";
                            for (int m = 0; m <= 9; ++m) {
                                r = "";
                                r = t + Integer.toString(m);
                                StringBuffer sb = new StringBuffer(r);
                                sb = sb.reverse();
                                r += sb.toString();
                                list.add(Integer.parseInt(r));
                            }

                        }

                    }
                }

            }
            int k = scan.nextInt();
            long ans = 0;
            long mod = scan.nextLong();
            int i = 0;
            for (int a : list) {
                if (i == k) break;
                ans = (ans + (long) a) % mod;
                i++;
            }
            out.println(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.*;
public class Test{
    public static void main(String[] afzal){
        Scanner sc = new Scanner(System.in);
        long K = sc.nextLong();
        long P = sc.nextLong();
        String str = Long.toString(K);
        str = str+str;
        long A = Long.parseLong(str);
        for(long i=K-1;i>=1;i--){
            str = Long.toString(i);
            str = str+str;
            long B = Long.parseLong(str);
            A = A+B;
        }
        System.out.println(A+" "+A%P);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        int[] pow = new int[12];

        public void solve(int testNumber, InputReader in, FastWriter out) {
            int k = in.nextInt();
            int mod = in.nextInt();

            pow[0] = 1;
            for (int i = 1; i < pow.length; ++i)
                pow[i] = NumberTheory.multiply(pow[i - 1], 10, mod);

            int[] kk = {k};
            int res = 0;
            int n = 1;
            do {
                int[] a = new int[n];
                res += compute(0, a, n, kk, mod);
                n++;
            } while (kk[0] > 0);
            out.println(res);
        }

        private int compute(int pos, int[] a, int n, int[] k, int mod) {
            if (k[0] <= 0) return 0;

            if (pos == n) {
                int res = 0;
                for (int i = n - 1; i >= 0; i--) {
                    int temp = NumberTheory.multiply(a[i], NumberTheory.add(pow[i], pow[2 * n - i - 1], mod), mod);
                    res = NumberTheory.add(res, temp, mod);
                }
                k[0]--;
                return res;
            }
            int res = 0;
            for (int digit = (pos == 0) ? 1 : 0; digit < 10 && k[0] > 0; ++digit) {
                a[pos] = digit;
                res = NumberTheory.add(res, compute(pos + 1, a, n, k, mod), mod);
            }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }

    static class FastWriter extends PrintWriter {
        public FastWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public FastWriter(Writer writer) {
            super(writer);
        }

        public FastWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

    }

    static class NumberTheory {
        public static int multiply(int a, int b, int mod) {
            long product = a * (long) b;
            if (product >= mod)
                product %= mod;
            return (int) product;
        }

        public static int add(int a, int b, int mod) {
            long sum = a + (long) b;
            if (sum >= mod)
                sum %= mod;
            return (int) sum;
        }

    }
}

import java.io.*;
import java.util.StringTokenizer;

public class B {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static long[] numbs = new long[100002];
    static long sum = 0;

    private static void calc(int k) {
        int counter = 0;
        for (int j = 1; j < 10; j++) {
            numbs[counter++] = j + j * 10;
        }

        int base = 10;
        while(counter < k) {
            base = base * 100;

            int d = (int)Math.ceil(Math.log10(base + 0.5f));

            int cur = counter;
            for (int h = 0; h < 9; h++) {
                int nextBase = base + h * (int)Math.pow(10f, d - 1)  + (h + 1);
                for (int j = 0; j < cur; j++) {
                    int curD = (int)Math.ceil(Math.log10(numbs[j] + 0.5f));
                    int power = d - curD;
                    numbs[counter++] = nextBase + numbs[j] * (int)Math.pow(10f, power / 2);

                    if (counter >= k) {
                        return;
                    }
                }
            }
        }
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int p = in.nextInt();

            calc(k);

            for (int j = 0; j < k; j++) {
                sum += numbs[j];
                sum %= p;
            }

            out.println(sum);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

import java.util.*;
import java.io.*;

public class B_Chthollys_Request {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		int p = in.nextInt();
		double num = 0;
		int digit;
		String pali;

		for(int i = 1; i <= k; i++){
			pali = "";
			int mult = i;
			while(mult != 0){
				digit = mult%10;
				pali += digit;
				mult /= 10;
			}
			if((Integer.parseInt(pali) + 1)%10 == 1) continue;
			System.out.println(i + pali);
			num += Double.parseDouble(i + pali);

		}

		System.out.print((int)(num % p));

	}

}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextInt();
        long p = sc.nextInt();
        long c = 0;
        for(long i=1;i<=k;i++)
        {
            String temp = "";
            temp = String.valueOf(i);
            temp = temp+temp;
            long s = Long.parseLong(temp);
            c = c + s;
        }
        System.out.println(c%p);
    }
}

import java.io.*;
import java.util.*;

public class Main {
    static long sum (long a[]) {
        long res = 0;
        int n = a.length;
        for (int i = 0; i < n; i++) res += a[i];
        return res;
    }

    static void solve() throws IOException {
        rl();
        int k = ni2(), p = ni2();
        long res = 0;
        boolean stop = false;

        if (k > 0) {
            for (int i = 1; i <= 9; i++) {
                long add = 11 * i;
                res += add;
//                System.out.println(add);
                k --;
                if (k <= 0) break;
            }
            res %= p;
        }

        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    long add = i1 * 1001 + i2 * 110;
                    res += add;
//                    System.out.println(add);
                    k--;
                    if (k <= 0){
                        stop = true;
                        break;
                    }
                }
                if (stop) break;
            }
        }

        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    for (int i3 = 0; i3 <= 9; i3++) {
                        long add = i1 * 100001 + i2 * 10010 + i3 * 1100;
                        res += add;
//                        System.out.println(add);
                        k--;
                        if (k <= 0){
                            stop = true;
                            break;
                        }
                    }
                    res %= p;
                    if (stop) break;
                }
                if (stop) break;
            }
        }

        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    for (int i3 = 0; i3 <= 9; i3++) {
                        for (int i4 = 0; i4 <= 9; i4++) {
                            long add = i1 * 10000001 + i2 * 1000010 + i3 * 100100 + i4 * 11000;
                            res += add;
//                            System.out.println(add);
                            k--;
                            if (k <= 0){
                                stop = true;
                                break;
                            }
                        }
                        res %= p;
                        if (stop) break;
                    }
                    if (stop) break;
                }
                if (stop) break;
            }
        }

        if (k > 0) {
            for (int i1 = 1; i1 <= 9; i1++) {
                for (int i2 = 0; i2 <= 9; i2++) {
                    for (int i3 = 0; i3 <= 9; i3++) {
                        for (int i4 = 0; i4 <= 9; i4++) {
                            for (int i5 = 0; i5 <= 9; i5++) {
                                long add = (long)i1 * 1000000001 + i2 * 100000010 + i3 * 10000100 + i4 * 1001000 + i5 * 110000;
                                res += add;
//                                System.out.println(add);
                                res %= p;
                                k--;
                                if (k <= 0){
                                    stop = true;
                                    break;
                                }
                            }
                            if (stop) break;
                        }
                        if (stop) break;
                    }
                    if (stop) break;
                }
                if (stop) break;
            }
        }

        res %= p;

        ans.append(res);
        output.write(ans.toString());
        output.flush();
        output.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
    static StringBuilder ans = new StringBuilder();
    static String line;
    static StringTokenizer stringTokenizer;

    static int ni1() throws IOException {
        return Integer.parseInt(input.readLine());
    }

    static int ni2() throws IOException {
        return Integer.parseInt(stringTokenizer.nextToken());
    }

    static long nl1() throws IOException {
        return Long.parseLong(input.readLine());
    }

    static long nl2() {
        return Long.parseLong(stringTokenizer.nextToken());
    }

    static void rl() throws IOException {
        stringTokenizer = new StringTokenizer(input.readLine());
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.KeyStore.Entry;
import java.time.temporal.JulianFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.JLabel;

public class answertillD {
	static int minn;

	static class pair implements Comparable<pair> {
		int u;
		int v;

		public pair(int uo, int vo) {
			u = uo;
			v = vo;

		}

		@Override
		public String toString() {
			return "pair [u=" + u + ", v=" + v + "]";
		}

		@Override
		public int compareTo(pair e) {
			if (u == e.u && v == e.v)
				return 0;
			if (u > e.u || e.u > u)
				return u - e.u;
			else
				return 1;
		}
	}

	static class edge implements Comparable<edge> {
		int u;
		int v;
		int w;

		@Override
		public String toString() {
			return "edge [u=" + u + ", v=" + v + ", w=" + w + "]";
		}

		public edge(int uo, int vo, int wo) {
			u = uo;
			v = vo;
			w = wo;
		}

		@Override
		public int compareTo(edge e) {
			// TODO Auto-generated method stub
			return w - e.w;
		}
	}

	public static long power(long x, long y) {
		long ans = 1;
		while (y-- > 0) {
			if (ans <= 1e18 / x)
				ans *= x;
			else {
				ans = Long.MAX_VALUE;
				break;
			}
		}
		return ans;
	}

	public static char[][] reb() {
		int n = smallArr.length;
		char[][] arr = new char[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				arr[i][j] = smallArr[n - j - 1][i];

		return arr;
	}

	static int[] Arr, cost, level;
	static char[][] smallArr;
	static boolean[][] memo;
	static int n;
	static long S;
	static final int VISITED = 2, EXPLORED = 1, UNVISITED = 0;
	static ArrayList<Integer>[] adjList;
	static boolean[] visited, adjMat[];
	static int V, E;

	static long bfs(String str, int k) {
		Queue<String> q = new LinkedList<String>();
		q.add(str);
		HashSet<String> hs = new HashSet<String>();
		hs.add(str);
		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		hm.put(str, 0);
		long ans = 0;
		while (k > 0 && !q.isEmpty()) {
			String u = q.remove();
			for (int v = 0; v < u.length(); v++) {
				String sam = u.substring(0, v) + u.substring(v + 1);
				if (!hm.containsKey(sam)) {
					int x = hm.get(u) + 1;
					hm.put(sam, x);
					k--;
					ans += x;
					if (k == 0)
						break;
					q.add(sam);
				}
			}

		}
		if (k != 0)
			return -1;
		return ans;

	}

	public static long GCD(long a, long b) {
		if (b == 0)
			return a;
		return GCD(b, a % b);
	}

	public static long powerlog(long x, long y, int mod) {
		long res = 1; // Initialize result
		while (y > 0) {
			if ((y & 1) == 1)
				res = (res * x);
		//	res %= mod;
			y = y >> 1; // y = y/2
			x = (x * x);
		//	x %= mod;
		}
		return res;
	}

	public static String rev(String str) {
		StringBuilder sb = new StringBuilder();
		for (int i = str.length() - 1; i >= 0; i--) {
			sb.append(str.charAt(i));
		}
		return sb + "";
	}

	public static boolean checj(int numa, int b, int a, int n, int k) {
		int numb = n - numa;
		if (k % a == 0) {
			if (k / a - 1 < numa)
				return false;
		} else {
			if (k / a < numa)
				return false;
		}
		k -= numa * a;
		if (k % b == 0) {
			if (k / b - 1 < numb)
				return false;
		} else {
			if (k / b < numb)
				return false;
		}
		return true;
	}

	static int mod;
	static String ans;
	static int[] arr;

	public static boolean dp(int idx, int rem) {
		if (idx == n)
			return rem % mod == 0;

		if (!memo[idx][rem])
			return memo[idx][rem];
		if (cost[idx] != -1) {
			arr[idx] = cost[idx];
			return memo[idx][rem] = dp(idx + 1, (int) ((rem + cost[idx] * powerlog(10, n - 1 - idx, mod)) % mod));

		}
		boolean flag = false;
		for (int i = 0; i < 10; i++) {
			if (idx == 0 && i == 0)
				continue;
			arr[idx] = i;
			flag = dp(idx + 1, (int) ((rem + i * powerlog(10, n - idx - 1, mod)) % mod));
			if (flag)
				break;
		}

		return memo[idx][rem] = flag;
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int p = sc.nextInt();
		long ans=0;
		long sum=0;
		int shift1=0;
		int shift2=0;
		int shift3=0;
		int shift4=0;
		int shift5=0;
	outer:	for (int i = 0; i < 10; i++) {
		if(i==1)shift1++;
			long r=powerlog(10, 0, p)*i+powerlog(10, 11, p)*i;
			sum+=r;
		//	sum%=p;
			for (int j = 0; j < 10; j++) {
				if(j==1)shift2++;
				int sumssss=shift1;
				long q=powerlog(10, 0+sumssss, p)*j+powerlog(10, 9+sumssss, p)*j;
				sum+=q;
			//	sum%=p;
				for (int k = 0; k < 10; k++) {
					if(k==1)shift3++;
					int sumsss=shift1+shift2;
					long o=powerlog(10, 0+sumsss, p)*k+powerlog(10, 7+sumsss, p)*k;
					sum+=o;
					//sum%=p;
					for (int l = 0; l < 10; l++) {
						if(l==1)shift4++;
						int sumss=shift1+shift2+shift3;
						long z=powerlog(10, 0+sumss, p)*l+powerlog(10, 5+sumss, p)*l;
						sum+=z;
					//	sum%=p;
						for (int m = 0; m < 10; m++) {
							if(m==1)shift5++;
							int sums=shift1+shift2+shift3+shift4;
							long y=powerlog(10, 0+sums, p)*m+powerlog(10, 3+sums, p)*m;
							sum+=y;
							//sum%=p;
							for (int u = 0; u < 10; u++) {
								int sumsh=shift1+shift2+shift3+shift4+shift5;
								long x=powerlog(10, 0+sumsh, p)*u+powerlog(10, 1+sumsh, p)*u;
								sum+=x;
						//		System.out.println(sum);

								ans+=sum;
								sum-=x;
								ans%=p;
								if(sumsh==0&&u==0)
									continue;
								n--;
								if(n==0)break outer;

							}
							sum-=y;
						}
						sum-=z;
					}
					sum-=o;
				}
				sum-=q;
			}
			sum-=r;
		}
		pw.print(ans);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}

import java.util.*;
import java.io.*;

public class Chthollys_request {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int k = Integer.parseInt(st.nextToken());
		int p = Integer.parseInt(st.nextToken());
		long sum=0;
		for (int i=1;i<=k;i++) {
			StringBuilder s1= new StringBuilder(i+"");
			StringBuilder s2=s1.reverse();
			s1.append(s2);
			String s=s1.toString();
			sum += Long.parseLong(s);
		}
		pw.println(sum%p);
		pw.flush();
		pw.close();
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        int[] pow = new int[12];

        public void solve(int testNumber, InputReader in, FastWriter out) {
            int k = in.nextInt();
            int mod = in.nextInt();

            pow[0] = 1;
            for (int i = 1; i < pow.length; ++i)
                pow[i] = NumberTheory.multiply(pow[i - 1], 10, mod);

//        long start = 1, end = start * 10;
//        int j = 1;
//        int res = 0;
//        while (k > 0) {
//            for (long i = start; i < end && k > 0; i++, k--) {
//                res = add(res, multiply((int)(i%mod), pow[j], mod), mod);
//                long ii = i;
//                int r = j - 1;
//                while (ii != 0) {
//                    res = add(res, multiply((int) ii % 10, pow[r], mod), mod);
//                    r--;
//                    ii /= 10;
//                }
//                start *= 10;
//                end *= 10;
//            }
//            j++;
//        }
//
//        out.println(res);

            int[] kk = {k};
            int res = 0;
            int n = 1;
            do {
                int[] a = new int[n];
                res += NumberTheory.add(res, compute(0, a, n, kk, mod), mod);
                n++;
            } while (kk[0] > 0);
            out.println(res);
        }

        private int compute(int pos, int[] a, int n, int[] k, int mod) {
            if (k[0] <= 0) return 0;

            if (pos == n) {
                int res = 0;
                for (int i = n - 1; i >= 0; i--) {
                    int temp = NumberTheory.multiply(a[i], NumberTheory.add(pow[i], pow[2 * n - i - 1], mod), mod);
                    res = NumberTheory.add(res, temp, mod);
                }
                k[0]--;
                return res;
            }
            int res = 0;
            for (int digit = (pos == 0) ? 1 : 0; digit < 10 && k[0] > 0; ++digit) {
                a[pos] = digit;
                res = NumberTheory.add(res, compute(pos + 1, a, n, k, mod), mod);
            }
            return res;
        }

    }

    static class FastWriter extends PrintWriter {
        public FastWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public FastWriter(Writer writer) {
            super(writer);
        }

        public FastWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }

    static class NumberTheory {
        public static int multiply(int a, int b, int mod) {
            long product = a * (long) b;
            if (product >= mod)
                product %= mod;
            return (int) product;
        }

        public static int add(int a, int b, int mod) {
            long sum = a + (long) b;
            if (sum >= mod)
                sum %= mod;
            return (int) sum;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ahmed Ayman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static ArrayList<Long> a = new ArrayList<>();
        static int mod;

        static void generate(int size, StringBuilder sb, boolean start) {
            if (size == 0) {
                sb.append(sb.reverse());
                a.add(Long.parseLong(sb.toString()));
                return;
            }
            if (start) {
                for (int i = 1; i <= 9; i++) {
                    StringBuilder tmp = new StringBuilder();
                    tmp.append(sb.toString());
                    tmp.append(i);
                    generate(size - 2, tmp, false);
                }
            } else {
                for (int i = 0; i <= 9; i++) {
                    StringBuilder tmp = new StringBuilder();
                    tmp.append(sb.toString());
                    tmp.append(i);
                    generate(size - 2, tmp, false);
                }
            }
        }

        static void generate() {
            int size = 2;
            while (a.size() <= 100000) {
                generate(size, new StringBuilder(), true);
                size += 2;
            }
            Collections.sort(a);
            return;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int k = in.nextInt();
            mod = in.nextInt();
            long sum = 0;
            generate();
            for (int i = 0; i < k; i++) {
//            out.println(a.get(i));
                sum = (sum + a.get(i)) % mod;
            }
            out.println(sum);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}

import java.util.*;
public class zd{
	public static void main(String [] args){
	Scanner sc =new Scanner(System.in);int k = sc.nextInt(); int p = sc.nextInt();
	int sum = 0;
		for(int i = 1; i <= k; i++){
		sum += (i*10)+i;
		}
	System.out.print(sum%p);
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.KeyStore.Entry;
import java.time.temporal.JulianFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.JLabel;

public class answertillD {
	static int minn;

	static class pair implements Comparable<pair> {
		int u;
		int v;

		public pair(int uo, int vo) {
			u = uo;
			v = vo;

		}

		@Override
		public String toString() {
			return "pair [u=" + u + ", v=" + v + "]";
		}

		@Override
		public int compareTo(pair e) {
			if (u == e.u && v == e.v)
				return 0;
			if (u > e.u || e.u > u)
				return u - e.u;
			else
				return 1;
		}
	}

	static class edge implements Comparable<edge> {
		int u;
		int v;
		int w;

		@Override
		public String toString() {
			return "edge [u=" + u + ", v=" + v + ", w=" + w + "]";
		}

		public edge(int uo, int vo, int wo) {
			u = uo;
			v = vo;
			w = wo;
		}

		@Override
		public int compareTo(edge e) {
			// TODO Auto-generated method stub
			return w - e.w;
		}
	}

	public static long power(long x, long y) {
		long ans = 1;
		while (y-- > 0) {
			if (ans <= 1e18 / x)
				ans *= x;
			else {
				ans = Long.MAX_VALUE;
				break;
			}
		}
		return ans;
	}

	public static char[][] reb() {
		int n = smallArr.length;
		char[][] arr = new char[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				arr[i][j] = smallArr[n - j - 1][i];

		return arr;
	}

	static int[] Arr, cost, level;
	static char[][] smallArr;
	static boolean[][] memo;
	static int n;
	static long S;
	static final int VISITED = 2, EXPLORED = 1, UNVISITED = 0;
	static ArrayList<Integer>[] adjList;
	static boolean[] visited, adjMat[];
	static int V, E;

	static long bfs(String str, int k) {
		Queue<String> q = new LinkedList<String>();
		q.add(str);
		HashSet<String> hs = new HashSet<String>();
		hs.add(str);
		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		hm.put(str, 0);
		long ans = 0;
		while (k > 0 && !q.isEmpty()) {
			String u = q.remove();
			for (int v = 0; v < u.length(); v++) {
				String sam = u.substring(0, v) + u.substring(v + 1);
				if (!hm.containsKey(sam)) {
					int x = hm.get(u) + 1;
					hm.put(sam, x);
					k--;
					ans += x;
					if (k == 0)
						break;
					q.add(sam);
				}
			}

		}
		if (k != 0)
			return -1;
		return ans;

	}

	public static long GCD(long a, long b) {
		if (b == 0)
			return a;
		return GCD(b, a % b);
	}

	public static long powerlog(long x, long y, int mod) {
		long res = 1; // Initialize result
		while (y > 0) {
			if ((y & 1) == 1)
				res = (res * x);
			// res %= mod;
			y = y >> 1; // y = y/2
			x = (x * x);
			// x %= mod;
		}
		return res;
	}

	public static String rev(String str) {
		StringBuilder sb = new StringBuilder();
		for (int i = str.length() - 1; i >= 0; i--) {
			sb.append(str.charAt(i));
		}
		return sb + "";
	}

	public static boolean checj(int numa, int b, int a, int n, int k) {
		int numb = n - numa;
		if (k % a == 0) {
			if (k / a - 1 < numa)
				return false;
		} else {
			if (k / a < numa)
				return false;
		}
		k -= numa * a;
		if (k % b == 0) {
			if (k / b - 1 < numb)
				return false;
		} else {
			if (k / b < numb)
				return false;
		}
		return true;
	}

	static int mod;
	static String ans;
	static int[] arr;

	public static boolean dp(int idx, int rem) {
		if (idx == n)
			return rem % mod == 0;

		if (!memo[idx][rem])
			return memo[idx][rem];
		if (cost[idx] != -1) {
			arr[idx] = cost[idx];
			return memo[idx][rem] = dp(idx + 1, (int) ((rem + cost[idx] * powerlog(10, n - 1 - idx, mod)) % mod));

		}
		boolean flag = false;
		for (int i = 0; i < 10; i++) {
			if (idx == 0 && i == 0)
				continue;
			arr[idx] = i;
			flag = dp(idx + 1, (int) ((rem + i * powerlog(10, n - idx - 1, mod)) % mod));
			if (flag)
				break;
		}

		return memo[idx][rem] = flag;
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int p = sc.nextInt();
		long ans = 0;
		long sum = 0;
		int shift1 = 0;
		int shift2 = 0;
		int shift3 = 0;
		int shift4 = 0;
		int shift5 = 0;
		outer: for (int i = 0; i < 10; i++) {
			if (i == 1)
				shift1++;
			long r = powerlog(10, 0, p) * i + powerlog(10, 11, p) * i;
			sum += r;
			// sum%=p;
			for (int j = 0; j < 10; j++) {
				if (j == 1&&i==0)
					shift2++;
				int sumssss = shift1;
				long q = powerlog(10, 0 + sumssss, p) * j + powerlog(10, 9 + sumssss, p) * j;
				sum += q;
				// sum%=p;
				for (int k = 0; k < 10; k++) {
					if (k == 1&&j==0&&i==0)
						shift3++;
					int sumsss = shift1 + shift2;
					long o = powerlog(10, 0 + sumsss, p) * k + powerlog(10, 7 + sumsss, p) * k;
					sum += o;
					// sum%=p;
					for (int l = 0; l < 10; l++) {
						if (l == 1&&k==0&&j==0&&i==0)
							shift4++;
						int sumss = shift1 + shift2 + shift3;
						long z = powerlog(10, 0 + sumss, p) * l + powerlog(10, 5 + sumss, p) * l;
						sum += z;
						// sum%=p;
						for (int m = 0; m < 10; m++) {
							if (m == 1&&l==0&&k==0&&j==0&&i==0)
								shift5++;
							int sums = shift1 + shift2 + shift3 + shift4;
							long y = powerlog(10,  sums, p) * m + powerlog(10, 3 + sums, p) * m;
							sum += y;
							// sum%=p;
							for (int u = 0; u < 10; u++) {
								int sumsh = shift1 + shift2 + shift3 + shift4 + shift5;
								long x = powerlog(10, sumsh, p) * u + powerlog(10, 1 + sumsh, p) * u;
								sum += x;
								System.out.println(sumsh+" "+sum);

								ans += (sum % p);
								sum -= x;
								ans %= p;
								if (sumsh == 0 && u == 0)
									continue;
								n--;
								if (n == 0)
									break outer;

							}
							sum -= y;
						}
						sum -= z;
					}
					sum -= o;
				}
				sum -= q;
			}
			sum -= r;
		}
		pw.print(ans);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}

import java.util.ArrayList;
import java.util.Scanner;

public class bb {
	static ArrayList<Integer> elm;
	public static long gen(int k, int p) {
	elm =new ArrayList<Integer>();
		long sum = 0;
		for(int i = 11;i<=99;i+=11) {
			elm.add(i);
			sum= (sum+i)%k;
			if(elm.size()==p)
				return (int)sum;
		}
		for(int i = 1001;i<=9999;i++) {
			String cur = i+"";
			boolean yes = true;
			for (int j = 0; j < cur.length()/2; j++) {
				if(cur.charAt(j)!=cur.charAt(cur.length()-1-j)) {
					yes = false;
					break;
				}
			}
			if(!yes)
				continue;
			elm.add(i);
			sum= (sum+i)%k;
			//System.out.println(elm.size());
			if(elm.size()==p)
				return (int)sum;

		}
		int inner = 1100;
		int inner2 =10010;
		int inner3 = 100001;
		int i = 100001;
		int count1 = 0;
		int count2 = 0;
		int count3 = 1;
		while(true) {
			int cur = count1*inner+count2*inner2+count3*inner3;
		//	System.out.println(cur);
			elm.add(cur);
			sum= (sum+cur)%k;
		//	System.out.println(elm.size());
			if(elm.size()==p)
				return (int)sum;
			count1++;
			if(count1==10&&count2==9&&count3==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					count2=0;
				}
				count1=0;
			}
		}
		i = 10000001;
		inner = 11000;
		inner2 =100100;
		inner3=1000010;
		int inner4= 10000001;
		count1 = 0;
		count2 = 0;
		count3= 0;
		int count4=1;
		while(true) {
			int cur = count1*inner+count2*inner2+count3*inner3+count4*inner4;

			elm.add(cur);
			sum= (sum+cur)%k;
		//	System.out.println(cur);
			if(elm.size()==p)
				return (int)sum;

			count1++;
			if(count1==10&&count2==9&&count3==9&&count4==9)
				break;
			if(count1==10) {
				count2++;
				if(count2==10) {
					count3++;
					if(count3==10) {
						count3=0;
						count4++;
					}
					count2=0;
				}
				count1=0;
			}

		}
		sum = (sum+1000000001)%k;
		return sum;

	}
public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int k = sc.nextInt();
	int p = sc.nextInt();

	System.out.println(gen(p,k));

}
}

import java.io.*;
import java.util.*;

public class Solution {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong(), p = scanner.nextLong(), result = 0;
		for (int i = 1; i < n + 1; i++) {
		    String st = String.valueOf(i);
		    st  += new StringBuilder(st).reverse();
		    result += Long.parseLong(st)%p;
		}
		System.out.printf("%d", result);
	}
}

import java.util.*;
public class B897 {
public static void main(String[] args)
{
	Scanner input = new Scanner(System.in);
	int n = input.nextInt(), k = input.nextInt();
	long res = 0;
	int count = 0;
	for(int length = 2; length <= 10; length++)
	{
		int start = 1;
		for(int j = 0; j<length/2-1; j++) start *= 10;
		for(int i = start; i < start * 10; i++)
		{
			count++;
			res += reverse(i) + (i * start * 10);
			res %= k;
			if(count == n)
			{
				System.out.println(res%k);
				return;
			}
		}
	}
}
static long reverse(int x)
{
	long res = 0;
	while(x > 0)
	{
		res *= 10;
		res += x%10;
		x /= 10;
	}
	return res;
}
}

import java.util.ArrayList;
import java.util.Scanner;

public class palindrome {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		long b = scan.nextLong();
		int sum = 0;
		long s3 = 0;
		ArrayList<Long> arr = new ArrayList<Long>();
		for(int i =1;i<a+1;i++){
			String s = Integer.toString(i);
			String s1 = "";
			String s2 = "";
			for(int j =0;j<s.length();j++){
				s1 = s1+s.charAt(j);
			}
			for(int j =s.length();j>0;j--){
				s2 = s2+s.charAt(j-1);
			}
			s = s1+s2;

			s3 = Long.parseLong(s);
			arr.add(s3);

		}
		for(int i =0;i<arr.size();i++){
			sum+=arr.get(i);
		}
		System.out.println(sum%b);

	}

}

import java.util.Scanner;

public class chthollysRequest {

	public static long calcSum(long k)
	{
		if(k<10)
		{
			long sum=0;

			for(int i=1;i<=k;i++)
			{
				sum=sum+i+(i*10);
			}

			return sum;
		}

		long i=0;
		while(Math.pow(10, i)<k)
			{
				i++;
			}

		long smallans=calcSum((long)Math.pow(10, i-1)-1);
		smallans=smallans*10;
		k=k-(long)Math.pow(10, i-1)-1;

		long d=k/10;
		long r=k%10;
		long sum=smallans;
		for(int j=1;j<=d;j++)
		{
			sum=sum+(j*10);
			sum=sum+(i*10*(long)(Math.pow(10, i)));
		}

		return sum;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner s=new Scanner(System.in);
		long k=s.nextInt();
		long p=s.nextInt();

		long sumans=calcSum(k);
		System.out.println(sumans%p);

	}

}

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class B {

	int len(int n) {
		return (""+n).length();
	}

	boolean isPalin(int n) {
		String s = ""+n;
		for(int i = 0, j = s.length() - 1; i <= j; ++i, --j) {
			if(s.charAt(i) != s.charAt(j)) return false;
		}
		return true;
	}

	long rev(long n) {
		String srev = new StringBuilder(""+n).reverse().toString();
		return Integer.parseInt(srev);
	}

	long makeNum(long a, long b) {
		return Long.parseLong(""+a+b);
	}

	public void solve(Scanner in, PrintWriter out) {
		ArrayList<Long> evenPalins = new ArrayList<>();
		for(long i = 1; i <= 101000; ++i) {
			long newNum = makeNum(i, rev(i));
			evenPalins.add(newNum);
		}
		long[] sum = new long[evenPalins.size()];
		for(int i = 0; i < evenPalins.size(); ++i) {
			sum[i] = evenPalins.get(i);
			if(i > 0) sum[i] += sum[i - 1];
		}
		int n = in.nextInt();
		int p = in.nextInt();
		out.println(sum[n - 1] % p);
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		new B().solve(in, out);

		in.close();
		out.close();
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class B_449 {

	public static String getnum(int num) {
		String s = Integer.toString(num);
		int i = s.length()-1;
		StringBuilder sb = new StringBuilder();
		for(int j = i; j >= 0 ; j--) {
			sb.append(s.charAt(j));
		}
		StringBuilder rev = new StringBuilder();
		for(int k = 0; k <= i; k++) {
			rev.append(s.charAt(k));
		}

		return sb.toString()+rev.toString();
	}

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int k = scn.nextInt();
		int p = scn.nextInt();

		long res = 0;
		for(int i = 1; ; i++) {
			if(k == 0) break;
			long n = Long.parseLong(getnum(i));
//			System.out.println(n);
			res += n;
			res %= p;
			k--;
		}
		System.out.println(res);

	}

}

import java.util.*;
public class Task897B {
	static int k, p;
	static int[] pow = new int[12];
	static int go(int t){
		int dig = (int) (Math.floor(Math.log10(t))+1);
		int ret = 0;
		for(int i = 0; i < dig; i++){
			ret += (t/(Math.pow(10,  i)) % 10) * (pow[i] + pow[2*dig - i - 1]) ;
			ret %= p;
		}
		return ret;

	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		p = sc.nextInt();
		int ret = 0;
		pow[0] = 1;
		for(int i = 1; i < 12; i++)
			pow[i] = (pow[i-1] * 10) % p;

		for(int i = 1; i <= k; i++){
			ret += go(i);
			ret %= p;
		}
		System.out.print(ret);
	}
}

import java.util.ArrayList;
import java.util.Scanner;

public class bb {
	static ArrayList<Integer> elm;
	public static int gen(int k, int p) {
	elm =new ArrayList<Integer>();
		long sum = 0;
		for(int i = 11;i<=99;i+=11) {
			elm.add(i);
			sum= (sum+i)%k;
			if(elm.size()==p)
				return (int)sum;
		}
		for(int i = 1001;i<=9999;i++) {
			String cur = i+"";
			boolean yes = true;
			for (int j = 0; j < cur.length()/2; j++) {
				if(cur.charAt(j)!=cur.charAt(cur.length()-1-j)) {
					yes = false;
					break;
				}
			}
			if(!yes)
				continue;
			elm.add(i);
			sum= (sum+i)%k;
			if(elm.size()==p)
				return (int)sum;

		}
//		System.out.println(elm.size());
	return 0;
	}
public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int k = sc.nextInt();
	int p = sc.nextInt();
	System.out.println(gen(p,k));

}
}

import java.util.*;
public class Test{
    public static void main(String[] afzal){
        Scanner sc = new Scanner(System.in);
        long K = sc.nextLong();
        long P = sc.nextLong();
        String str = Long.toString(K);
        str = str+str;
        long A = Long.parseLong(str);
        for(long i=K-1;i>=1;i--){
            str = Long.toString(i);
            str = str+str;
            long B = Long.parseLong(str);
            A = A+B;
        }
        System.out.println(A%P);
    }
}

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class b {

	static class N
	{
		ArrayList<Integer> digits = new ArrayList<>();

		public int add(int index)
		{
			if(index == -1)
			{
				digits.add(0, 1);
				return 1;
			}

			if(digits.get(index) == 9)
			{
				int move = add(index-1);
				digits.set(index+move, 0);
				return 0;
			}

			digits.set(index, digits.get(index)+1);
			return 0;
		}

		public long val()
		{
			long ret = 0;
			long mult = 1;

			for(int i=0; i<digits.size(); i++)
			{
				ret +=	digits.get(i)*mult;
				mult *= 10;
			}

			for(int i=digits.size()-1; i>=0; i--)
			{
				ret +=	digits.get(i)*mult;
				mult *= 10;
			}

			return ret;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int count = in.nextInt();
		int mod = in.nextInt();

		N build = new N();

		long out = 0;
		for(int i=0; i<count; i++)
		{
			build.add(build.digits.size()-1);
			out = (out + build.val())%mod;
		}
		System.out.println(out);

	}

//	public static int go(StringBuilder number, int mod, boolean isFirst)
//	{
//		if(made >= count) return 0;
//
//
//
//		i = 0;
//		if(isFirst) i = 1;
//		for(; i<9; i++)
//		{
//			number.append(i+'0');
//			ret = (ret + go(number, mod, false))%mod;
//			number.deleteCharAt(number.length()-1);
//			made++;
//			if(made >= count) return ret;
//		}
//
//		return ret;
//	}
//
//	public static int val(int number, boolean isFirst)
//	{
//
//		StringBuilder cpy = new StringBuilder(number.toString());
//
//		for(int i=number.length()-1; i>=0; i--)
//			cpy.append(number.charAt(i));
//
//		return Integer.valueOf(cpy.toString());
//	}

}

/*
20
11 + 22 + 33 + 44 + 55 + 66 + 77 + 88 + 99 + 1001 + 1111 + 1221 + 1331 + 1441 + 1551 + 1661 + 1771 + 1881 + 1991 + 2002

30
11 + 22 + 33 + 44 + 55 + 66 + 77 + 88 + 99 + 1001 + 1111 + 1221 + 1331 + 1441 + 1551 + 1661 + 1771 + 1881 + 1991 + 2002 + 2112 + 2222 + 2332 + 2442 + 2552 + 2662 + 2772 + 2882 + 2992 + 3003
 */

import java.util.Scanner;
public class Chtholly_request_897B
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int p = sc.nextInt();
		int sum=0;
		for(int i=1, num=0, num1;i<=k;i++)
		{
			num = i;
			num1 = num;
			while(num1>0)
			{
				num = num*10+num1%10;
				num1/=10;
			}
			sum+=num%p;
			sum%=p;
		}
		System.out.println(sum);
		sc.close();
	}
}

import java.util.Scanner;

public class Main {

    static String rev(String s)
    {
        String res = "";
        for (int i = s.length()-1; i>=0; --i)
            res+= s.charAt(i);
        return  res;
    }
    static long gen(long left, boolean ev)
    {
        String s = ""+left;
        String r = rev(s);
        if (ev) s = s+r;
        else s = s+ r.substring(1);
        return  Long.parseLong(s);
    }

    static  long solve(int k, long mod)
    {
        long res = 0;
        for (long i = 1; i< 10; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, true);
            res%= mod;
            k--;
        }

        for (long i = 11; i< 100; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, false);
            res%= mod;
            k--;
        }

        for (long i = 11; i< 100; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, true);
            res%= mod;
            k--;
        }

        for (long i = 101; i< 1000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, false);
            res%= mod;
            k--;
        }

        for (long i = 101; i< 1000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, true);
            res%= mod;
            k--;
        }

        for (long i = 1001; i< 10000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, false);
            res%= mod;
            k--;
        }

        for (long i = 1001; i< 10000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, true);
            res%= mod;
            k--;
        }

        for (long i = 10001; i< 100000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, false);
            res%= mod;
        }

        for (long i = 10001; i< 100000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, true);
            res%= mod;
        }

        for (long i = 100001; i< 1000000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, false);
            res%= mod;
        }

        for (long i = 100001; i< 1000000; ++i)
        {
            if (k <=0) return  res;
            res =res+ gen(i, true);
            res%= mod;
        }

        return  res;
    }

    public static void main(String[] args) {
        Scanner sc =  new Scanner(System.in);
        long res = 0;
        int k= sc.nextInt();
        int m = sc.nextInt();
        System.out.print(solve(k, m));
        // write your code here
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc=new FastReader();
	   long sum=0;
	    int k=sc.nextInt();
	    long p=sc.nextLong();
	    for(int i=1;i<=k;i++)
	    {
	       //
	       // int val=ispalin(i);
	       // System.out.println()
	       // if(dig%2==0 && val==1){
	           // k--;

	        long x = 11 * i;
	        int dig=(int)Math.ceil(Math.log10(x));
	        if(dig%2==0)
	         sum = ((sum%p)+(x%p))%p;
	         //System.out.println(i+"    "+sum+"    "+k);
	         //sum = sum + x;

	    }
	    //sum=sum%p;
	    // String ans = new String(a);
	     System.out.println(sum);

	}

}
class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.util.Scanner;

public class Eieve {

    public static void main(String args[]) {

        Scanner input = new Scanner(System.in);

        long k = input.nextInt(), p = input.nextInt(), j = 11, i1 = 0, sum = 0;

        for (int i = 1; i <= k; i++) {
            i1 = i * 10 + i % 10;
            sum = sum + i1;
        }
        System.out.println(sum % p);

    }

}

import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class Main implements Runnable {

	String file = "input";
    boolean TEST = System.getProperty("ONLINE_JUDGE") == null;

    void solve() throws IOException {
    	int k = nextInt(), p = nextInt();
    	int res = 0;
    	for (int i = 1; i <= k; i++) {
    		StringBuilder a = new StringBuilder(i + "");
    		a.append(a.reverse());
    		res += Long.parseLong(a.toString());
    		res %= p;
    	}
    	out.println(res);
    }

    String next() throws IOException {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    void debug(Object... o) {
        System.out.println(deepToString(o));
    }

    void gcj(Object o) {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException {
        if (TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

    public static void main(String[] args) throws IOException {
        new Thread(null, new Main(), "", 1 << 20).start();
    }

    public void run() {
        try {
            init();
            if (TEST) {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            } else solve();
            out.close();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author caoash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BChthollysRequest solver = new BChthollysRequest();
        solver.solve(1, in, out);
        out.close();
    }

    static class BChthollysRequest {
        public void solve(int testNumber, FastScanner br, PrintWriter pw) {
            int k = br.nextInt();
            int MOD = br.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                StringBuilder curr = new StringBuilder(Integer.toString(i));
                String ans = curr.append(curr.reverse()).toString();
                sum += Long.parseLong(ans);
                sum %= MOD;
            }
            pw.println(sum);
            pw.close();
        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastScanner.SpaceCharFilter filter;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.Scanner;

public class Chtholly_request_897B
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int p = sc.nextInt();
		StringBuffer s;
		int count=0, i=1;;
		int sum=0;
		do
		{
			s = new StringBuffer(Integer.toString(i));
			if(s==s.reverse())
			{
				sum+=i%p;
				sum%=p;
				count++;
			}
			i++;
		}
		while(count<k);
		System.out.println(sum);
//		int sum=0;
//		for(int i=0;i<5;i++)
//		{
//			sum+=sc.nextInt()%12;
//			sum %=12;
//			System.out.println(sum);
//		}

	}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class HelloWorld {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);

		int k = in.nextInt();
		int p = in.nextInt();
		long sum = 0;
		int count = 0;
		long currentElement = 1;
		while(count < k) {
			if(currentElement % 10 == 0) {
				currentElement++;
				continue;
			}
			else {
				String number = Long.toString(currentElement);
				String newNumber = number + (new StringBuilder(number).reverse().toString());
				//System.out.println(number);
				sum = (sum + Long.parseLong(newNumber)) % p;
				currentElement++;
				count++;
			}
		}
		System.out.println(sum);
	}
}

import java.util.*;
public class zd{
	public static void main(String [] args){
	Scanner sc =new Scanner(System.in);int k = sc.nextInt(); int p = sc.nextInt();
	int sum = 0;
	for(int i = 1; i <= k; i++){
		int icopy = i;
		while(icopy>0){
			sum += (i*10)+(i%10);
			icopy /=10;
		}
	}
	System.out.print(sum%p);
	}

}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CF443A {
	static MyScanner in = new MyScanner();
	static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

	static boolean isZcy(long n) {
		String s = String.valueOf(n);
		if (s.length() % 2 == 1) {
			return false;
		}
		String reverse = new StringBuilder(s).reverse().toString();
		return reverse.equals(s);
	}

	public static void main(String[] args) {
		long ans = 0;
		long k = in.nextInt(), p = in.nextInt();
		long i = 11, toAdd = 11;

		while (k > 0) {
			// System.out.println(i);
			long len = String.valueOf(i).length();
			if (len % 2 == 1) {
				String s = "1";
				for (long j = 0; j < len - 1; j++) {
					s += "0";
				}
				s += "1";
				toAdd *= 10;
				i = Long.valueOf(s);
			}
			// if (isZcy(i)) {
			k--;
			ans += i;
			ans %= p;
			// }
			i += toAdd;
		}
		out.println(ans);
		// out.print(count > 0 ? "YES" : "NO");
		// long k = in.nextLong();
		// String s = in.next();
		// int[] arr = new int[n];
		// for (int i = 0; i < n; i++) {
		// arr[i] = in.nextInt();
		// }

		/*
		 * Dont delete
		 */
		out.close();
		/*
		 *
		 */
	}

	// BIN seach
	// while (l != r) {
	// mid = (l + r) / 2;
	// if (check(mid)) {
	// ans = mid;
	// l = mid + 1;
	// } else {
	// r = mid;
	// }
	// }
	public static long GCD(long a, long b) {
		return b == 0 ? a : GCD(b, a % b);
	}

	public static long LCM(long a, long b) {
		return a * b / GCD(a, b);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class B_449 {

	public static String getnum(int num) {
		String s = Integer.toString(num);
		int i = s.length()-1;
		StringBuilder sb = new StringBuilder();
		for(int j = i; j >= 0 ; j--) {
			sb.append(s.charAt(j));
		}
		StringBuilder rev = new StringBuilder();
		for(int k = 0; k <= i; k++) {
			rev.append(s.charAt(k));
		}

		return sb.toString()+rev.toString();
	}

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int k = scn.nextInt();
		int p = scn.nextInt();

		long res = 0;
		for(int i = 1; ; i++) {
			if(k == 0) break;
			long n = Long.parseLong(getnum(i));
//			System.out.println(n);
			res += n;
			res %= p;
			k--;
		}
		System.out.println(res);

	}

}