Dramatic Multiplication

Time limit2sMemory limit128 MB

Summary
Find the smallest positive integer X ending in digit k such that multiplying X by n equals X with its last digit moved to the front.
Level

Medium5 of 10

Topics
Math, Number theory, Simulation
Solved
No attempts yet

Problem

For a positive integer X, let R(X) be the number obtained by moving the last decimal digit of X to the front. For example, if X = 102564, then R(X) = 410256.

A positive integer X is called n-dramatic if n × X = R(X).

Given n and k, find the smallest n-dramatic number whose last digit is k. If no such number exists, print 0. The decimal representation of the number cannot start with 0.

Input

The first line contains n and k separated by a space.

1 ≤ n ≤ 9, 1 ≤ k ≤ 9

Output

Print the smallest n-dramatic number whose last digit is k. If no such number exists, print 0.

Examples2

  1. Example 1

    Input
    4 5
    
    Expected output
    128205
    
  2. Example 2

    Input
    2 1
    
    Expected output
    0