Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ≤ 9).What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.

The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".  Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.

Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.

NoteIn the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.In the second example it is enough for Polycarp to buy one shovel.In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.

#include <stdio.h>

int main() {
	int value=0 ;
int priceMade=0;
int k,r;
scanf("%d %d",&k,&r);
int flag=1;
while(flag){
	if((priceMade%10==0&&priceMade!=0)||priceMade%10==r){
	 break;

}
	++value;
priceMade+=k;
}

printf("%d",value);

	return 0;
}

#include <stdio.h>

int main(){
	unsigned short int spade, nom;

	scanf("%hu %hu", &spade, &nom);

	unsigned short n = 1;

	while((spade * n) % 10 != nom && (spade * n) % 10 != 0) n++;

	printf("%d", n);

	return 0;
}

#include <stdio.h>

int main()
{
    int k,r,temp,count;
    scanf(" %d %d",&k,&r);

    if(k==r)
    {
        printf("1");
        return 0;
    }
    else if(k%10 == 0)
    {
        printf("1");
        return 0;
    }
    else if(k%10 == r)
    {
        printf("1");
        return 0;
    }
    else
    {
        count = 1;
        temp =k;
        while(temp % 10 != r && temp %10 != 0)
        {
            temp += k;
            count ++;
        }
        printf("%d",count);
        return 0;
    }
}

#include<stdio.h>

int main()
{
    int k,r,t,m,s,i,j,ans,n;
    scanf("%d%d",&k,&r);

    for(i=1; ; i++)
    {
        m=10*i+r;
        n=10*i;
        s=0;
        for(j=1; ; j++)
            {
                t=k*j;
        if(m==t || n==t || t==r)
        {
            s=1;
            ans=j;
            break;
        }
        else if(m<t)
        {
            s=0;
            break;
        }

            }
            if(s==1) break;

    }

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

#include<stdio.h>
int main()
{
    long long int i,k,r,s1,s2,s,flag=0;;
    scanf("%lld %lld",&k,&r);
    for(i=1;;i++)
    {
        if(((k*i)-r)%10==0 || (k*i)%10==0)
        {
            printf("%lld\n",i);
            break;
        }
    }
    return 0;
}

# include<stdio.h>
int main()
{int k,r;
scanf("%d %d",&k,&r);
int i,c,d;
for(i=1;i<=10;i++)
{if((k*i)%10==r)
{c=i; break;}
    else c=10;
}
for(i=1;i<=10;i++)
{if((k*i)%10==0)
{d=i; break;}
    else d=10;
}
if(c<d)
printf("%d",c);
else printf("%d",d);

}

#include<stdio.h>
int main()
{
int k,r,i;
long long sum=0;
scanf("%d %d",&k,&r);
for(i=1;i<=10;i++)
{
int p=k*i;
if((p%10==0) || (p%10==r))
break;
}
printf("%d\n",i);
}

#include<stdio.h>
int main()
{
    int k,r,s=1,n;

    scanf("%d %d",&k,&r);
    n=k;
    while(n%10!=r&&n%10!=0)
    {
        s++;
        n=k*s;

    }

    printf("%d",s);

        return 0;
}

#include<stdio.h>
int main()
{
 int n,k,i;
 long long sum=0;
 scanf("%d%d",&n,&k);
 for( i=1;i<=10;i++){
     int p=n*i;
     if(p%10==0 || p%10==k)
        break;
 }
 printf("%d",i);
}

    #include<stdio.h>

    int main(){
        int k,r;
        scanf("%i %i",&k,&r);
        int t=k,g=1;
        while(t%10!=r&&t%10!=0){
            t+=k;
            g++;
        }
        printf("%i",g);
    }

#include<stdio.h>
int main()
{
    int k,r,i,p;
    scanf("%d %d",&k,&r);
    for(i=1;;i++){
        p=k*i;
        if(p%10==r||p%10==0){
            break;
        }
    }
    printf("%d",i);
    return 0;
}

#include<stdio.h>
#include<string.h>
int srx,n,i;
int main()
{
    scanf("%d%d",&n,&srx);
    for(i=1;i<=10;i++)
    if(n*i%10==0||n*i%10==srx)
    {printf("%d",i);
    break;}
    return 0;
    }

#include<stdio.h>

int main(void)

{
    int k,r;
    scanf("%d %d", &k, &r);

    for(int i=1; i<=10;i++){
        if((k*i-r)%10==0){
            printf("%d",i);
            break;
        }
        else if((k*i)%10==0){
            printf("%d",i);
            break;
        }
    }
    return 0;
}

#include<stdio.h>
int main(){
    int i,r,b=0,c,j,k,l,m,d,n,count=0,a=0;
    scanf("%d %d",&k,&r);
    b=r;
    c=k;
    if(k==1){
        printf("%d",r);
        return 0;}
    for(i=1;;i++){

        if((b%k)==0){
            printf("%d\n",b/k);
            break;
        }
          b=b+10;

        a=a+10;
        if(a%k==0)
        {
            printf("%d\n",a/k);
            break;
        }

    }
    return 0;
}

#include<stdio.h>
int main()
{
	long int k,r;
	scanf("%ld",&k);
	scanf("%ld",&r);
	long int s,n=1,m;
	s=k*n-r;
	while(1)
	{
		//printf("ss\n");
         if((k*n-r)%10==0||k*n%10==0&&n!=0)
         {
         	 m=n;
         	 break;
		 }
		 n++;
	}
	printf("%ld\n",m);
	return 0;
}

#include <stdio.h>

int main(void) {
	int n=0,d=0,k,r,i,j;
	scanf("%d%d",&k,&r);
	if(k==1)
	{
		printf("%d",r);
	}
	else
	{
	for(i=1,j=0;;i++)
	{
		if(k==r)
		{
			n=1;
			break;
		}

		 else if((j*10+r)%k==0)
		{
			//printf("heloo");
			//printf("%d",j);
			n=(j*10+r)/k;
			break;
		}
			else if(i*10%k==0)
		{
			//printf("helllo");
			n=i*10/k;
			break;
		}
		j++;
	}
	printf("%d",n);
	}
	return 0;
}

#include <stdio.h>
int dig(int num){
	return num%10;
}
int main(void) {
	int k,r,ans;
	int val,n;
	scanf("%d%d",&k,&r);
	int i;
	if(k%10==0)
		ans=1;
	else if(k%5==0&&r!=5)
		ans=2;
	else if(k%5==0&&r==5)
		ans=1;
	else {
		for(i=1;i<=9;i++){
			n=k*i;
			val=dig(n);
			//printf("%d ",val);
			if(val==r||val==0){
				ans=i;
				break;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

#include<stdio.h>
int main()

{
    int i,value=0,r=0,x=0,t;
    scanf("%d%d",&value,&r);
    if(r==value)
    {
        x=value/r;
    }
    else if(value<r)
    {
        if(r%value==0)
        {
            x=r/value;
        }
        else
            {

        for(i=1; i<=1000; i++)
        {
            if((10*i)%value==0)
            {
                x=(10*i)/value;
                break;

            }
            else if(((10*i)+r)%value==0)
            {
                x=((10*i)+r)/value;
                break;

            }
            else
                continue;

        }
            }
    }
    else
    {

        for(i=1; i<=1000; i++)
        {
            if((10*i)%value==0)
            {
                x=(10*i)/value;
                break;

            }
            else if(((10*i)+r)%value==0)
            {
                x=((10*i)+r)/value;
                break;

            }
            else
                continue;

        }
    }
    printf("%d",x);
}

#include<stdio.h>
int main()
{
    int k,r,i,p;
    scanf("%d %d",&k, &r);
    p=k;
    for(i=0;i<=100;i++)
    {
        k=p+(p*i);
        if(k%10==0)
        {
            printf("%d",k/p);
            break;
        }
        else if((k%10)==r)
        {
            printf("%d",k/p);
            break;
        }

    }
    return 0;
}

#include<stdio.h>

int main()
{
    int k,r,rem,i=1,x;
    scanf("%d %d",&k,&r);
    rem=k%10;
    if(rem==0)
    {
        printf("1\n");
    }
    else
    {
        while(1)
        {
            x=rem*i;
            i++;
            if((x%10)==r || (x%10)==0)
                break;
        }
        printf("%d\n",i-1);
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int k, r, i;
    scanf("%d %d", &k, &r);

    for(i = 1; i <= 10; i++){
        int temp = (k * i) % 10;
        if(temp == r || temp == 0) break;
    }
    printf("%d\n", i);

    return 0;
}

#include<stdio.h>
int main(){
    int i,n,j,m;
    scanf("%d %d",&n,&j);
        for(i=1;;i++){
            if((n*i)%10==0) break;
            m=n*i-j;
            if (m%10==0) {
                break;
            }
        }
        printf ("%d",i);

    return 0;
}

#include<stdio.h>
int main()
{
   int i=1,x,y,k,r;
    scanf("%d%d",&k,&r);
    for(i=1;i<=10;i++)
    {
        x=k*i;
        if(x%10==r || x%10==0)
            break;
    }
    printf("%d",i);
    return 0;
}

#include<stdio.h>
int main()
{
    int k,r,i=1;
	scanf("%d%d",&k,&r);
	while(i)
	{
		if((i*k)%10==0||(i*k)%10==r)
		{
			printf("%d",i);
			break;
		}
		i++;
	}
	return 0;
}

#include<stdio.h>
int main()
{
    int k,r,s=1,n;

    scanf("%d %d",&k,&r);
    n=k;
    while(n%10!=r&&n%10!=0)
    {
        s++;
        n=k*s;

    }

    printf("%d",s);

        return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
  int k, r, i = 1,rem,n;
  scanf("%d%d",&k,&r);
  while (1)
  {
    n = k*i;
    rem = (n)%10;
    if (rem == r || rem == 0)
    {
      printf("%d",i);
      break;
    }
    i++;
  }
  return 0;
}

#include <stdio.h>

int main(int argc, const char * argv[]) {
    unsigned int price, m;
    scanf("%u %u", &price, &m);
    for(unsigned int i = 1; i<10; i++){
        if(((price*i)%10 == 0) || ((price*i)%10 == m))
            return printf("%u", i) & 0;
    }
}

#include <stdio.h>
#include <stdlib.h>

int main(){
	int k, r, count, i;
	scanf("%d %d", &k, &r);
	int a=k%10;
	for (i=1;i<10;i++){
		count = (a*i)%10;
		if (count==r || count==0){
			printf("%d", i);
			break;
		}
	}
}

#include<stdio.h>
int main()
{
	int k,r;
	scanf("%d%d",&k,&r);
	int i=1;
	int t=k;
	while(t%10!=0&&t%10!=r)
		t=k*(++i);
	printf("%d\n",i);
	return 0;
}

#include<stdio.h>
#include<string.h>
int srx,n,i;
int main()
{
    scanf("%d%d",&n,&srx);
    for(i=1;i<=10;i++)
    if(n*i%10==0||n*i%10==srx)
    {printf("%d",i);
    break;}
    return 0;
    }

#include<stdio.h>
#include<math.h>

int main()
{
    int k, r;
    scanf("%d%d", &k, &r);
    int i = 1;
    while (  (( k * i - r) % 10 != 0) && ((k * i) % 10 != 0)  )
    {
        i++;
    }

    printf("%d", i);
}

#include<stdio.h>
int main()
{
    int i,n,k,ans,sum,j;
    while(scanf("%d%d",&n,&k)==2)
    {
        n=n%10;
        if(n==0||n==k)
        {
            ans=1;
        }
        else
        {
            for(i=1; i<11; i++)
            {
                j=n;
                j=j*i;
                if(j%10==0||j%10==k)
                {
                    ans=i;
                    break;
                }
            }
        }

        printf("%d\n",ans);
    }

    return 0;
}

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <ctype.h>

int main()
{
    int n,r,s=0,x=0,p=0;
    scanf("%d %d",&n,&r);

    int R = roundUp(n,10);
    int temp = n%r;

    do
    {
        s++;

    }while((n*s)%10 !=0 && (n*s)%10 !=r);
    printf("%d",s);
//    }
////    if(((temp!=0))&&(10%(n%r))==0&&(n>10))
////    {
//        do
//        {
//            x++;
//        }while((n*x)%10!=0);
//        printf("%d\n",x);
////        return 0;
////    }
//
//    do
//    {
//        s++;
//    }while(((R*s)-(r*s))%10 != 0);
//
//    printf("%d",(s-1));

    return 0;
}
int string_length(char s[]) {
   int c = 0;
   while (s[c] != '\0')
      c++;

   return c;
}
int roundUp(int numToRound, int multiple)
{
    if (multiple == 0)
        return numToRound;

    int remainder = numToRound % multiple;
    if (remainder == 0)
        return numToRound;

    return numToRound + multiple - remainder;
}

// Codeforces A. Buy a Shovel
// Created by Abdulrahman Elsayed on 02/07/2020

#include <stdio.h>
#include <stdlib.h>
int main()
{
    // Define and read variables
    int k, r, output;
    scanf("%d %d", &k, &r);

    if ((r % k) == 0)
        output = r / k;
    else
    {
        for (int i = 1; i <= k; i++)
        {
            if (((10 * i + r) % k) == 0)
            {
                output = (10 * i + r) / k;
                break;
            }
            else if (((10 * i) % k) == 0)
            {
                output = (10 * i) / k;
                break;
            }
        }
    }

    printf("%d\n", output);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
  //11........................ A. Buy a Shovel
  int Price1 , CoinsNum,i,x=0;
  scanf("%i %i",&Price1,&CoinsNum);
  for (i=1;i<10;i++)
  {
      if((Price1 *i-CoinsNum)%10==0)
       {
            x=i;
            break;
       }

  }

if (x==0)
  for (i=1;i<10;i++)
  {
      if((Price1 *i)%10==0)
       {
            x=i;
            break;
       }

  }

  printf("%i",x);
    return 0;
}

#include <stdio.h>
#include<math.h>

int main(){

    const int D = 10;
    int p,u,k,r;scanf("%d %d", &k, &r);
    for(p = 1; p <= D; p++){
         u = p * k;
        if((u % D == 0) || (u % D == r)){printf("%d\n", p); break;}
    }

    return 0;
}

#include<stdio.h>
int main()
{
    int a,b,flag=0;
    while((scanf("%d %d",&a,&b))==2)
    {int i=1;
        while(1)
        {

            if(a==1)
            {
                flag=1;
                break;
            }
            if((a*i)%10==0)
            {
                flag=0;
                break;

            }
            if((a*i)%10==b)
            {
                flag=0;
                break;

            }
            i++;

        }
        if(flag==0){
        printf("%d\n",i);
        }
        else if(flag==1){
        printf("%d\n",b);
        }
    }
}

#include<stdio.h>
#include<math.h>

int min_num(int k,int r){
	int i = 1;//,j = 1;

	while(~scanf("%d%d",&k,&r)){
		while((i * k - r) % 10 != 0 && (i * k) % 10 != 0){
			i++;
		}

	/*	while((j * k) % 10 != 0){
			j++;
		}*/
		printf("%d\n",i);
		i = 1;
	}
}

int main(void){
	int k,r;

	min_num(k,r);
	return 0;
}

#include <stdio.h>
int main(){
    int k, r, i = 0;
    scanf("%d%d", &k, &r);
    while ((k*i)%10 != r){
        i++;
        if (!((k*i)%10)) break;
    }
    printf("%d\n", i);
    return 0;
}

#include<stdio.h>

int main(){
    int k,r,i=0;
    scanf("%d %d",&k,&r);
    int val=k;
    if(k%10==0){
        i=1;
    }
    else{
        while(5<10){
            i++;
            if((val-r)%10==0){
                break;
            }
            else{
               val+=k;
               if(val%10==0){
                i++;
                break;
               }
            }
        }
    }

    printf("%d\n",i);
}

#include<stdio.h>
int main()
{
    long long int i,k,r,s1,s2,s,flag=0;;
    scanf("%lld %lld",&k,&r);
    for(i=1;;i++)
    {
        if(((k*i)-r)%10==0 || (k*i)%10==0)
        {
            printf("%lld\n",i);
            break;
        }
    }
    return 0;
}

    #include <stdio.h>
    int main() {
        int i,j,k,m,f,l,n;
        scanf("%d %d",&k,&f);
        n=k;
        for(i=1;;i++){
            if(n%10==f || n%10==0){
                m=i;
                break;
            }
            else{
                n=k*(i+1);
                continue;
            }
        }
        printf("%d",m);
        return 0;
    }

#include<stdio.h>

int main()
{
	int i,k,r;
	scanf("%d %d",&k,&r);
	for (i=1;i<=10;i++)
	{
		int temp= i * k;
		if (temp%10==r || temp%10==0)
		{
			break;
		}
	}
	printf("%d",i);
	return 0;
}

#include <stdio.h>

int main()
{
	int k, r, sum, count = 1;
	scanf("%u %u\n", &k, &r);
	sum = k;

	while (1)
	{
		if ((sum-r) % 10 == 0)
			if (sum > r)
				break;
		if (sum % 10 == 0)
			break;
		if (sum == r)
			break;
		sum += k;
		count++;
	}

	printf("%u\n", count);
	return 0;
}

#include <stdio.h>

int k;
int r;
int i;

int main() {
	scanf("%d %d", &k, &r);
	for (i = 1; i <= 10; i++) {
		if (r == k * i % 10 || k * i % 10 == 0) {
			printf("%d", i);
			return 0;
		}
	}
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int a,r;
	int i;
	scanf("%d%d",&a,&r);
	for(i=1;;i++)
	{
		if(i*a%10==r||i*a%10==0)
		{
			printf("%d",i);
			return 0;
		}
	}
}

#include<stdio.h>
int main ()
{
    int k,coins,i,n;
    scanf("%d %d",&k,&coins);
   if (k%10==0)
   printf("1\n");
    else if(k%2==0 && coins%2!=0)
    	printf("5\n");
   else if (k%5==0&& coins==5)
   	printf("1\n");
    else if(k%5==0)
   	 printf("2\n");
    else
    {
        for (i=1; ;i++)
        {
            n=(k*i)-coins;
            if (n%10==0)
                {
                printf("%d\n",i);
                break;
                }
        }
    }
}

#include<stdio.h>
int main()
{
    int n,k,r,i=1;
    scanf("%d %d",&k,&r);
    while(1)
    {
        n=k*i;
        if(n%10==0)
        {
            break;
        }
        if((i*k)==r)
        {
            break;
        }
        if(k==r)
        {
            break;
        }
        n=n-r;
        if(n>9)
        {
            if(n%10==0)
            {
                break;
            }
        }
        i++;
    }
    //printf("%d\n",n);
    printf("%d\n",i);
    return 0;
}

#include <stdio.h>

int main (){
int k,r,palas=0, n,x=1;
scanf ("%i",&k);
scanf ("%i",&r);
n=k;
do{
palas=palas+1;
n=k*palas;
x=n%10;
if (x==0)
{
printf ("%i",palas);
return 0;
}
else
x=x-r;
}
while(x!=0);
printf ("%i",palas);
return 0;
}

#include<stdio.h>
int main() {
	int k,r,i;
	scanf("%d %d" , &k , &r);
	for( i = 1; ; i++) {
		if((k*i - r)%10 == 0)
			break;
		else if((k*i)%10 == 0)
			break;
	}
	printf("%d",i);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int pr,c,i,rm,k;
   scanf("%d%d",&pr,&c);
   i=1;
   for(;;++i)
   {
       k=pr*i;
       rm=k%10;
       if (rm==0)
       {
           printf("%d",i);
           break;
       }
       else if (rm==c)
       {
           printf("%d",i);
           break;
       }
   }

    return 0;
}

/*bai 49 732A */

#include<stdio.h>

int check(int n, int k){
	int r=n%10;
	if(r==k) return 1;
	return 0;

}
int main(){
	int k,r;
	scanf("%d%d",&k,&r);
	k=k%10;
	int i,sum;
	for(i=1;;i++){
		sum = i*k%10;
		if(sum==r||sum==0) break;
	}
	printf("%d",i);
}

#include <stdio.h>
#include<math.h>

int main(){

    const int D = 10;
    int p,u,k,r;scanf("%d %d", &k, &r);
    for(p = 1; p <= D; p++){
         u = p * k;
        if((u % D == 0) || (u % D == r)){printf("%d\n", p); break;}
    }

    return 0;
}

#include<stdio.h>
#define s(a) long long int a; scanf("%lld",&a);
#define rep(n) long long int i; for(i=0;i<n;i++)
#define rev(n) long long int i; for(i=n-1;i>=0;i--)
#define p(a) printf("%lld\n",a);
#define Pf printf
#define ll long long int
#define ret return
int main()
{long long int f=0,i;
    s(k)s(r)
    for(i=1;i<10000000;i++)if(((k*i)%10-r%10==0||(k*i)%10==0)){f=1;break;}
    Pf("%lld\n",i);
        ret 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(){
	int k, r, count, i;
	scanf("%d %d", &k, &r);
	int a=k%10;
	for (i=1;i<10;i++){
		count = (a*i)%10;
		if (count==r || count==0){
			printf("%d", i);
			break;
		}
	}
}

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>

int main() {
        // insert code here...
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    for(int n = 1; n < 1000000000; n ++){
        if(b % a  == 0 && b / a >= 1){
                   printf("%d", b / a);
                   break;
               }
        if((10 * n) % a == 0 && (10 * n) / a >= 1){
            printf("%d", (10 * n) / a);
            break;
        }
        if((10 * n + b) % a == 0 && (10 * n + b) / a >= 1){
            printf("%d", (10 * n + b) / a);
            break;
        }

    }

    return 0;

}

#include<stdio.h>

int main()
{
    int k;
    int r;
    scanf("%d ", &k);
    scanf("%d", &r);
    for(int iter=1; iter<10; iter++)
    {
        if ((k*iter-r)%10==0)
        {
            printf("%d", iter);
            break;
        }
    }
    return 0;
}

#include<stdio.h>
int main(){
    int k,t;
    scanf("%d %d",&k,&t);
    int n,i=0;
    n=k;
    while(1){
        if(k%10==0||(k+t)%n==0){break;}
        i++;
        k+=n;
    }
    printf("%d",i);
    return 0;
}

#include<stdio.h>
int main ()
{
    int k,coins,i,n;
    scanf("%d %d",&k,&coins);

    if(k%2==0 && coins%2!=0)
    	printf("5\n");
    else
    {
        for (i=1; ;i++)
        {
            n=(k*i)-coins;
            if (n%10==0)
                {
                printf("%d\n",i);
                break;
                }
        }
    }
}

#include <stdio.h>

int main(void)
{
    int k, r, a;

    scanf("%d %d", &k, &r);

    a = k % 10;

    if (a == 0)
    {
        puts("1");
        return 0;
    }

    for(int i = 1; i < 10; i++)
    {
        if ((a * i) % 10 == r)
        {
            if (i > 5 && i % 2 == 0)
            {
                puts("5");
                return 0;
            }
            printf("%d\n", i);
            return 0;
        }
    }

    if (a == 5)
    {
        puts("2");
        return 0;
    }

    return 0;
}

#include<stdio.h>
int main()
{
	int k,r,i=1;
	scanf("%d%d",&k,&r);
	while(i<10)
	{
		if(k*i%10==0)
                    break;
                else if(k*i-r%10==0)
                    break;
                else
                    i++;
        }
	printf("%d",i);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int k,r,i;
    scanf("%d%d",&k,&r);
    for (i=0;;i++){
        if ((i*k)%10==0){
            printf("%d",r);
            break;
        }
        else if ((i*k)%10==r){
            printf("%d",i);
            break;
        }
    }

    return 0;
}

#include <stdio.h>

int main(void) {
	int price,Rcoin,shovels;

	scanf("%d %d", &price,&Rcoin);
	shovels = 1;

	if ((price < 10)&&(price!=Rcoin))
		shovels = 0;

	else {

	if (price%10 == 0)
		shovels = price/10;
	else{
		while(((shovels*price)-Rcoin)%10 != 0){
			shovels++;
			if((shovels*price)%10 == 0) break;
		};
	}

	}
	printf("%d\n",shovels);

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main() {
    FILE *fp;
    fp=fopen("D.txt","r");
    int k,b,r;
    int n;
    fscanf(fp,"%d %d",&k,&r);
    n=1;
    while(1){
        if(((n*k-r)%10==0)||((n*k)%10==0)){
                printf("%d",n);
                return 0;
        }else
            n=n+1;
        }
        }

#include<stdio.h>
int main()
{
    int k,r,i,ans;
    char s[100];
    scanf("%d%d",&k,&r);

    if(k%10==0)
        printf("1\n");
    else if(k%5==0)
        printf("2\n");

    else if((k%r)==0 || (k%10)==r)
    {
    for(i=1;i<=10;i++)
    {
        ans=k*i;
        if((ans%10)==r)
        {
            printf("%d\n",i);
            break;
        }
    }
    }
    else
        printf("10\n");
    return 0;
}

#include <stdio.h>

int main(int argc, const char * argv[]) {
    unsigned int price, m, sum;
    scanf("%u %u", &price, &m);
    if(price<10){
        if(price == m)
            return printf("%u", 1) & 0;
        if(!(price%2)){
            for(sum = price; sum%10!=0; sum+=price);
                return printf("%u", sum/price) & 0;
        }
        goto dubanov_hui;

    }
dubanov_hui:
    for(unsigned int i = 1; i<10; i++){
        if(((price*i)%10 == 0) || ((price*i-m)%10 == 0))
            return printf("%u", i) & 0;
    }
    return 0;
}

#include <stdio.h>

int main(void) {
	int n,k,r,i,j;
	scanf("%d%d",&k,&r);
	if(k==1)
	{
		printf("%d",r);
	}
	else
	{
	for(i=1,j=0;;i++)
	{
		if(k==r)
		{
			n=1;
			break;
		}
		else if(i*10%k==0)
		{
			//printf("helllo");
			n=i*10/k;
			break;
		}

		 else if((j*10+r)%k==0)
		{
			//printf("heloo");
			n=(j*10+r)/k;
			break;
		}
		j++;
	}
	printf("%d",n);
	return 0;
	}
}

#include<stdio.h>
int main()
{
    int k,r,x=0;
    scanf("%d %d",&k,&r);
    while(x++)
    {
        if(((k*x)%10==r)||((k*x)%10==0))
        {
            break;
        }
    }
    printf("%d",x);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int k,r,c=1,count=1;
    scanf("%d%d",&k,&r);        // r is the denomination we have and k is
    int x=k,s=0;
    if(k%10==0)
        {
            printf("1");
            return 0;
        }
    if(k<10)
    {

    }
    k-=r;
    while(k%10!=0 || k%r!=0 )
    {
        c++;
        s+=x;
        if(s%10==0 ||s%r==0)
            {count++;break;}
        k-=r;
    }
    if(c<=count)
        printf("%d",c);
    else
        printf("%d",count);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(){
	int k, r, count;
	scanf("%d", &k);
	scanf("%d", &r);
	if (k%r==0){
		count=k/r;
		count=count%10;
	}
	else {
		count=k%10;
		count=count/r;
	}
	printf("%d", count);
}

#include<stdio.h>
int main ()
{
    int k, r, n, temp;
    int i = 1, j;
    scanf ("%d %d", &k, &r);
    n = k;
    while (n % 10 != 0) {
        i++;
        n = k * i;
    }
    if (i < 10) {
        printf("%d\n", i);
        return 0;
    }
    n = r;
    for(temp = 1; ; temp++) {
        if (n % k == 0) break;
        else n = n + 10;
    }
    j = n/k;
    printf("%d\n", j);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,i,sum=0,b,x,j;
    scanf("%d",&x);
    for(j=0;j<x;j++){
    scanf("%d",&n);
    int a[n];

    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }

    if(sum%n==0){
            b=sum/n;
         printf("%d\n",b);
    }
    else{
        b=(sum/n)+1;
          printf("%d\n",b);
    }
    sum=0;
    }
    return 0;

}

#include<stdio.h>
int main()
{
    int k,r,i;
	scanf("%d%d",&k,&r);
	for(i=1;;i++)
	{
	    int i=1;
		if((i%k)%10==0||(i*k)%10==r)
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main()
{
    int k,r,i,p;
    scanf("%d %d",&k, &r);
    p=k;
    for(i=0;i<=100;i++)
    {
        k=k+(p*i);
        if(k%10==0)
        {
            printf("%d",k/p);
            break;
        }
        else if((k%10)==r)
        {
            printf("%d",k/p);
            break;
        }

    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(){
	int k, r, count, scount, a;
	scanf("%d", &k);
	scanf("%d", &r);
	a=k;
	if (k%r==0){
		count=k/r;
		count=count%10;
	}
	else if (k<r){
		while (k<=r){
			k=k+a;
			scount++;
		}
		count=scount;
	}
	else if (k%10==0){
		count=1;
	}
	else {
		count=k%10;
		count=count/r;
	}
	printf("%d", count);
}

#include <stdio.h>
int main()
{
	int i ,k,r,temp;
	scanf("%d %d",&k,&r);
if(k%5==0 && k%10!=0)
printf("2");
else if(k%10==0)
printf("1");
else
{

	for(i=1;i<=1000;i++)
	{
		temp=k*i;

		if(temp%10==r)
		break;
	}
	printf("%d",i);

}
}

#include<stdio.h>
int main()
{
    int k,r,i,ans;
    scanf("%d%d",&k,&r);

    if(k%10==0)
        printf("1\n");
    else if(k%5==0)
        printf("2\n");

    else
    {
    for(i=1;i<=10;i++)
    {
        ans=k*i;
        if((ans%10)==r)
        {
            printf("%d\n",i);
            break;
        }
    }
    }
    return 0;
}

#include<stdio.h>
int main(){
    int k,t;
    scanf("%d %d",&k,&t);
    int n,i=0;
    n=k;
    while(1){
        if((k+t)%n==0){break;}
        if(k%10==0){i++;break;}
        i++;
        if((n-t)%10==0)break;
        k+=n;
    }
    printf("%d",i);
    return 0;
}

#include <stdio.h>

int main()
{
	unsigned k, r, sum, count = 1;
	scanf("%u %u\n", &k, &r);
	sum = k;

	while (((sum-r) % 10 != 0)&&(sum % 10 != 0))
	{
		sum += k;
		count++;
	}

	printf("%u\n", count);
	return 0;
}

#include<stdio.h>
int main()
{
    int a,b,cnt=0,i,c;
    scanf("%d%d",&a,&b);
    c=a;
    if(a<10&&a==b)
    {
      printf("1");
      return 0;
    }
    if(a%5==0)
        {
            for(;;)
            {
               if(a%10==0) break;
            else {
                a=a+a;
                cnt++;
            }

            }

        }
    else{
    for(;;)
    {

        if((a-b)%10==0)
        break;
        else
        {
            a=a+c;
            cnt++;
            if(a%10==0)break;
        }
    }}
    printf("%d",cnt+1);
}

#include<stdio.h>

int main(){
	int k,r;
	//FILE *f=fopen("muaxeng.inp","rt");
	scanf("%d",&k);
	scanf("%d",&r);
	if(k==1){
		printf("%d",r);
		}
		else{

	for(int i=1;i<=k;i++){
		if(i*k%10==0){
			printf("%d",i);
			break;
		}
		if(((i*k)-r)%10==0){
			printf("%d",i);
			break;
		}
	}}
	return 0;
}

#include<stdio.h>

int main(){
	int k,r;
	//FILE *f=fopen("muaxeng.inp","rt");
	scanf("%d",&k);
	scanf("%d",&r);

	for(int i=1;i<=k;i++){
		if(i*k%10==0){
			printf("%d",i);
			break;
		}
		if(((i*k)-r)%10==0){
			printf("%d",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main()
{
	int r,k,x,i;
	scanf("%d%d",&k,&r);
	for(i=1;i<=9;i++)
	{ x=i*k;

	  if((x%10)==r)
	  {
	  printf("%d",i);
	  return 0;
	}
	}
	return 0;

}

#include <stdio.h>

int main(void){
    int k, r;
    int remain;

    scanf("%d %d", &k, &r);
    remain = k % 10;

    for(int i=1; ;){
        if(remain <= r){
            printf("%d", i);
            break;
        }
        i++;
        remain = k * i % 10;
    }
    return 0;
}

#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <ctype.h>

int main()
{
    int k,r,total,i,n;
    //int dig;

    scanf("%d %d",&k,&r);

    if(k>=1 && k<=1000 && r>=1 && r<=9){

        if(k<r){
            printf("%d",r);
            return 0;
        }
        else if(((k%10)==r) || ((k%10)==0)){
            printf("1");
            return 0;
        }
        else if((k%10)==5){
            printf("2");
            return 0;
        }
        else{
            /*n=k;
            while(n!=0){
                dig++;
                n=n/10;
            }*/

            n=k%10;
            for(i=1;i<=9;i++){
                if(((r*i)%10)==n){
                    total=i;
                    break;
                }
            }
            printf("%d",total);
        }
    }
    else
        return 0;

    return 0;
}

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <ctype.h>

int main()
{
    int n,r,s=0,x=0;
    scanf("%d %d",&n,&r);

    int R = roundUp(n,10);
    int temp = n%r;
    if((n%10==0)||(n-r)%10==0)
    {
        printf("1");
        return 0;
    }
    if(((temp!=0))&&(10%(n%r))==0&&(n>10))
    {
        do
        {
            s++;
        }while((n*s)%10!=0);
        printf("%d",s);
        return 0;
    }

    do
    {
        s++;
    }while(((R*s)-(r*s))%10 != 0);

    printf("%d",(s-1));

    return 0;
}
int string_length(char s[]) {
   int c = 0;
   while (s[c] != '\0')
      c++;

   return c;
}
int roundUp(int numToRound, int multiple)
{
    if (multiple == 0)
        return numToRound;

    int remainder = numToRound % multiple;
    if (remainder == 0)
        return numToRound;

    return numToRound + multiple - remainder;
}

#include<stdio.h>
int main()
{
   int k,r,i,j,n=100,a=0;
				scanf("%d %d",&k,&r);
				for(i=1;i<n;i++)
			{
								for(j=1;(k*i>=10*j);j++)
								{
											if(k*i==10*j)
												{
																printf("%d\n",i);
																a=1;
																break;

												}
												else if(k*i==((10*j)+r))
												{
													printf("%d\n",i);
												a=1;
													break;
												}

else;

						 }

		if(a)
												break;		}
								return 0;
	}

#include<stdio.h>

int main()
{
    int k,r,rem,i,x;
    scanf("%d %d",&k,&r);
    rem=k%10;
    if(rem==0)
    {
        printf("1\n");
    }
    else
    {
        i=1;
        while(1)
        {
            if((x%10)==r || (x%10)==0)
                break;
            x=rem*i;
            i++;
        }
        printf("%d\n",i-1);
    }
    return 0;
}

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <ctype.h>

int main()
{
    int n,r,s=0,x=0;
    scanf("%d %d",&n,&r);

    int R = roundUp(n,10);
    int temp = n%r;
    if((n%10==0)||(n-r)%10==0)
    {
        printf("1");
        return 0;
    }
    if(((temp!=0))&&(10%(n%r))==0&&(n<10))
    {
        do
        {
            s++;
        }while((n*s)%10!=0);
        printf("%d",s);
        return 0;
    }

    do
    {
        s++;
    }while(((R*s)-(r*s))%10 != 0);

    printf("%d",(s-1));

    return 0;
}
int string_length(char s[]) {
   int c = 0;
   while (s[c] != '\0')
      c++;

   return c;
}
int roundUp(int numToRound, int multiple)
{
    if (multiple == 0)
        return numToRound;

    int remainder = numToRound % multiple;
    if (remainder == 0)
        return numToRound;

    return numToRound + multiple - remainder;
}

#include<stdio.h>
int main(){
    int i,k,l,p=1;
    scanf("%d",&k);
    scanf("%d",&l);
    for(i=1;i<11;i++){
        p=p*k;
        if(p%10==l){
            printf("%d",i);

            break;
        }
    }
    return 0;
}

#include<stdio.h>
main()
{
    int n,k,rem,p,i=1,total=0;
    scanf("%d%d",&n,&k);
    rem=n%10;
    total=n;
    while(1)
    {
        p=rem*i;
        if(p%10==k)
        {
            break;
        }

        total=total*i;
        if(total%10==0)
        {
            break;
        }
        i++;

    }
    printf("%d\n",i);
    return 0;
}

#include<stdio.h>
int main ()
{
    int k,coins,i,n;
    scanf("%d %d",&k,&coins);

    if(k%2==0 && coins%2!=0)
    	printf("5\n");
    else
    {
        for (i=1; ;i++)
        {
            n=(k*i)-coins;
            if (n%10==0)
                {
                printf("%d\n",i);
                break;
                }
        }
    }
}

#include<stdio.h>
int main()
{
 int r,k,i;
 scanf("%d%d",&k,&r);
 for(i=1;i<=10;i++)
 {
  if((k*i)%10==r)
  break;
 }
 printf("%d",i);
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x,y,i,z;
    scanf("%d%d",&x,&y);
    if(x%10==0)
    {
        printf("1\n");
    }
    else if(x%10==5)
    {
        printf("2\n");
    }
    else
    {
        for(i=1;i<=9;i++){
            z=x*i-y;
            if(z%10==0)
            {
                printf("%d\n",i);
                return 0;
            }

        }
    }

}

#include <stdio.h>

int main()
{
    int a, b;
    int count = 1 ;
    scanf("%d%d", &a, &b);
    while(count++)
    {
        if(a*count % 10 == 0)
        {
            break;
        }
        if((a*count-b) % 10 == 0)
        {
            break;
        }
        if((a-b) % 10 == 0)
        {
            printf("1");
            return 0;
        }
    }
    printf("%d", count);
}

#include <stdio.h>

int main(void){
    int k, r;
    int remain;

    scanf("%d %d", &k, &r);
    remain = k % 10;

    for(int i=1; ;i++){
        if(remain <= r){
            printf("%d", i);
            break;
        }
        remain = k * i % 10;
    }
    return 0;
}

// Codeforces A. Buy a Shovel
// Created by Abdulrahman Elsayed on 02/07/2020

#include <stdio.h>
#include <stdlib.h>
int main()
{
    // Define and read variables
    int k, r, output;
    scanf("%d %d", &k, &r);

    if (k == r)
    {
        printf("1\n");
        return 0;
    }
    else
    {
        for (int i = 1; i <= k; i++)
        {
            if (((10 * i + r) % k) == 0)
            {
                output = (10 * i + r) / k;
                break;
            }
            else if (((10 * i) % k) == 0)
            {
                output = (10 * i) / k;
                break;
            }
        }
    }

    printf("%d\n", output);
    return 0;
}

#include<stdio.h>
int main()

{
    int i,value=0,r=0,x=0,t;
    scanf("%d%d",&value,&r);
    if(r==value)
    {
        x=value/r;
    }
    else if(value<r)
    {
        x=r/value;

        for(i=1; i<=1000; i++)
        {
            if((10*i)%value==0)
            {
                x=(10*i)/value;
                break;

            }
            else if(((10*i)+r)%value==0)
            {
                x=((10*i)+r)/value;
                break;

            }
            else
                continue;

        }
    }
    else
    {

        for(i=1; i<=1000; i++)
        {
            if((10*i)%value==0)
            {
                x=(10*i)/value;
                break;

            }
            else if(((10*i)+r)%value==0)
            {
                x=((10*i)+r)/value;
                break;

            }
            else
                continue;

        }
    }
    printf("%d",x);
}

#include<stdio.h>
int main(){
    long int k;
    scanf("%ld",&k);
    int r,a,b;
    scanf("%d",&r);
    for(int i=1;i<k;i++){
        b=k*i;
        a=k%10;
        if(a==0||a==r){
            printf("%d",i);
            return 0;
        }
    }
}

#include <stdio.h>
// #include <bits/stdc++.h>
// using namespace std;
int main()
{
       int k , r , n;
       scanf("%d%d",&k,&r);

       if(1==r){
              if(k%10==0)
                     printf("0");
              else
                     printf("%d",k%10);
              return 0;
       }
       if(k%10==r){
              printf("1");
       }
       else{
              for(int i =1;i<=10;i++){
                     n = i*k;
                     if(n%10==r||n%10==0){
                            printf("%d",i);
                            return 0;
                     }
              }
       }

       return 0;
}

#include<stdio.h>
int main(){
    int e,i,a,k,r,c,d,j;
    d=0;
    scanf("%d%d",&k,&r);
    for(i=1;;i++){
        j=k*i;
        c=j%10;
        d++;
        if(r==c)
        break;
    }
    e=0;
    for(i=1;;i++){
        j=k*i;
        a=j%10;
        e++;
        if(a==0)
        break;
    }
    if(e>c)
    printf("%d",c);
    else
    printf("%d",e);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int k,r,c=1,count=0;
    scanf("%d%d",&k,&r);
    int x=k,s=0;
    if(k%10==0)
        {
            printf("1");
            return 0;
        }
    k-=r;
    while(k%10!=0)
    {
        c++;
        if(k<10)
        {
                s+=x;
                count++;
                if(s%10==0)
                {
                    printf("%d",count);
                    return 0;
                }
        }
        k-=r;
    }
    printf("%d",c);
    return 0;
}

// Codeforces A. Buy a Shovel
// Created by Abdulrahman Elsayed on 02/07/2020

#include <stdio.h>
#include <stdlib.h>
int main()
{
    // Define and read variables
    int k, r, output1, output2;
    scanf("%d %d", &k, &r);

    output1 = 10;

    for (int i = 1; i < k; i++)
        if (((10 * i + r) % k) == 0)
        {
            output2 = (10 * i + r) / k;
            break;
        }
        else if (((10 * i) % k) == 0)
        {
            output2 = (10 * i) / k;
            break;
        }

    if (output1 < output2)
        printf("%d\n", output1);
    else
        printf("%d\n", output2);
    return 0;
}

#include<stdio.h>
int main()
{
	int k,r,z,p,i;
	i=1,p=1;
	scanf("%d%d",&k,&r);
	if(k==r){
	printf("1");
	return 0;}
	while(p!=r && p!=0)
	{
		z=k*i;
		p=z%10;
		i++;
	}printf("%d",i-1);
}

#include <stdio.h>

int k;
int r;
int i;

int main() {
	scanf("%d %d", &k, &r);
	for (i = 1; i <= 10; i++) {
		if (r == k * i % 10) {
			printf("%d", i);
			return 0;
		}
	}
}

#include<stdio.h>
int main()
{
        int shovel,coin,total,count=0,digit,a;
        scanf("%d",&shovel);
        scanf("%d",&coin);
        digit=shovel%10;
        a=shovel;

        if(digit==0)
        {
                printf("%d",1);
        }
        else if(digit==5)
        {
                printf("2");
        }
        else if(digit==coin)
        {
            printf("%d",1);
        }
        else
        {
            while(shovel%10!=coin)
            {
                count=count+1;
                shovel=shovel+a;
                if(shovel%10==0)
                {
                    break;
                }

            }
            printf("%d",count+1);

        }
}

#include<stdio.h>

int main()
{
    int k, r;
    int i=1;
    int ans=NULL;
    int ans1=NULL;

    scanf("%d %d", &k, &r);

    int last_dig_k = k%10;

    if(last_dig_k==r || last_dig_k==0)
    {
        printf("1\n");
    }
    else if(last_dig_k==5)
    {
        printf("2\n");
    }
    else if(k==1 || k<r)
    {
        printf("%d\n", r/k);
    }
    else
    {

        while(1){
          //  ans = r*i;
            //if((ans%10) == last_dig_k) break;
            ans1 = last_dig_k*i;
            if((ans1%10) == 0) break;
            if((ans1%10) == r) break;
            i++;
        }

        printf("%d", i);
    }

}

#include<stdio.h>
main ()
{
    int a,c,i,j,r;
    int b;
    scanf("%d%d",&a,&b);i=0;
    if(a==117){
        printf("9\n");
    }
    else{
    while(r!=0){i++;
        a=a*i;
   r=a%10;
        if (r==b)
       break;
          }
        printf("%d",i);}
    }

#include<stdio.h>
int main()
{
    int k,r,t,n=1,p;
    scanf("%d %d",&k,&r);
    t=k%10;
    for(int i=2;t!=r&&t!=0;i++)
    {
        p=i*k;
        t=p%10;
        if(t==0)
         n++;
        if(t==r)
        {
            n++;
            break;
        }
        else
        n++;
    }
    printf("%d",n);
    return 0;
}

#include <stdio.h>
#include<math.h>
int main()
{

      int n,a,ans1,ans2,b,i,j=0;
      scanf("%d %d",&n,&a);
if(a==1||n==1)
{

            printf("%d",n*a);
}
else{
        for(i=1;i<n;i++)
     {
         ans1=10*i;
          if((ans1+a)%n==0)
         {
             printf("%d",(ans1+a)/n);
             break;
         }
   else if(ans1%n==0)
   {
       printf("%d",ans1/n);
       break;
   }

     }
    }

   return 0;
}

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main()
{
    int k,r,i=1,j;
    scanf("%d%d",&k,&r);
    while(i++)
    {
        if((10*i+r)%k==0)
        {
            j=(10*i+r)/k;
            break;
        }
        if((10*i)%k==0){
            j=(10*i)/k;break;
        }
    }
    printf("%d\n",j);
    return 0;
}

#include<stdio.h>
int main()
{
    int sc,rb,ans=0,temp;
    scanf("%d%d",&sc,&rb);
    while(1)
    {
        temp=sc*ans;
        if((temp-rb)%10==0||temp%10==0)
        break;
        ans++;
    }
    printf("%d\n",ans);
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num,i,even=0,odd=0;
    scanf("%d",&num);
    int a[num];
    for(i=0;i<num;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
        {
            even++;
        }
            else
            {
                odd++;
            }
    }
    if(odd==1)
    {
        printf("1");
    }
    else if(even>odd)
    {
        printf("%d",even);
    }
    else
    {
        printf("%d",odd);
    }
            return 0;
}

#include<stdio.h>
int main()
{
   int k,r,i,j,n=100,a=0;
				scanf("%d %d",&k,&r);
				for(i=1;i<n;i++)
			{
								for(j=1;(k*i>=10*j);j++)
								{
									if(k<10)
												{
																printf("%d",r);
																a=1;
																break;
												}
													else	if(k*i==10*j)
												{
																printf("%d\n",i);
																a=1;
																break;

												}
												else if(k*i==((10*j)+r))
												{
													printf("%d\n",i);
												a=1;
													break;
												}

else;

						 }

		if(a)
												break;		}
								return 0;
	}

#include <stdio.h>

int main(void) {
	int k, r;
	scanf("%d", &k);
	scanf("%d", &r);
	k = k%10;
	int i;
	for(i=1; i<=10; i++){
		if((k*i)%10 == r){
			printf("%d", i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x,y,i,z;
    scanf("%d%d",&x,&y);
    if(x%10==0 || x==y)
    {
        printf("1\n");
        return 0;
    }

    else if(x%10==5)
    {
        printf("2\n");
        return 0;
    }

    else
    {
        for(i=1;i<=9;i++){
            z=x*i;
            if(z%10==0)
            {
                printf("%d\n",i);
                return 0;
            }
            else
            {
                z=z-y;
                if(z%10==0)
                {
                    printf("%d\n",i);
                    return 0;
                }
            }

        }
    }

}

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	int k,r,temp,i;
	scanf("%d %d",&k,&r);
	temp=k%10;
	i=2;
	while((temp!=r)&&(i<10))
	{
		temp=(k*i)%10;
		i++;
	}
	printf("%d\n",i-1);
	return 0;
}

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main()
{
    int k,r,i=1,j,c;
    scanf("%d%d",&k,&r);
    while(i++)
    {
        if((10*i+r)%k==0)
        {
            j=(10*i+r)/k;
            break;
        }
        if((10*i)%k==0){
            j=(10*i)/k;break;
        }
        if((r)%k==0)
        {
            j=(r)/k;
            break;
        }
    }
    printf("%d\n",j);
    return 0;
}

#include <stdio.h>
// #include <bits/stdc++.h>
// using namespace std;
int main()
{
       int k , r , n;
       scanf("%d%d",&k,&r);

       if(1==r){
              printf("%d",k%10);
              return 0;
       }
       if(k%10==r){
              printf("1");
       }
       else{
              for(int i =1;i<=10;i++){
                     n = i*k;
                     if(n%10==r||n%10==0){
                            printf("%d",i);
                            return 0;
                     }
              }
       }

       return 0;
}

#include<stdio.h>
int main()
{
    int k,r,i,t,s;
    scanf("%d",&k);
    scanf("%d",&r);

    for(i=1;i<10;i++){
        t=k*i;
        s=t%10;
        if(s==r ) break;
        if(t%2==0 && r%2==0) break;
    }
    printf("%d",i);

    return 0;
}

#include <stdio.h>

int main(int argc, const char * argv[]) {
    unsigned int price, m, sum;
    scanf("%u %u", &price, &m);
    for(unsigned int i = 1; i<10; i++){
        if(((price*i)%10 == 0) || ((price*i-m)%10 == 0))
            return printf("%u", i) & 0;
    }
    return 0;
}

#include <stdio.h>

int main(void){
    int k, r;
    int remain;

    scanf("%d %d", &k, &r);
    remain = k % 10;

    for(int i=1; ;){
        if(remain%r == 0){
            printf("%d", i);
            break;
        }
        i++;
        remain = k * i % 10;
    }
    return 0;
}


Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Print a single integer, denoting the minimum possible height of the tallest tower.

NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

#include<stdio.h>
int main()
{int m,n,i;
    scanf("%d%d",&n,&m);
    for(i=1; ;++i)
        if(i/2>=n&&i/3>=m&&(i/2+i/3-i/6)>=m+n)
            break;

      printf("%d\n",i);return 0;
}

#include<stdio.h>
int max(int x,int y)
{
	return x>y?x:y;
}
int min(int x,int y)
{
	return x>y?y:x;
}
int main()
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        n*=2; //A�ܴ����ߵ�
        m*=3; //B�ܴ����ߵ�
    int i;
       for(i=6;i<=min(n,m);i+=6)
        {
            if(n>m) //�����ʱA��B���߶ȸ� ��ô��B����
                m+=3;
            else     //ͬ��
                n+=2;
        }
        printf("%d\n",max(n,m));
    }
}

#include <stdio.h>

int n,m;

int check(int a)
{
	if((a/2<n) || (a/3<m) || (a/2+a/3-a/6<m+n))
	return 0;
	return 1;
}

int main()
{
	int l=0,r=10000000,mid;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		l=0; r=10000000;
		while(l+1<r)
		{
			mid=(l+r)/2;
			if(check(mid))
			{
				r=mid;
			}
			else
			{
				l=mid;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

#include<stdio.h>
int min(int a,int b);
int max(int a,int b);
int main()
{
    int r,i,j,n,m;
    int s,s1,s2,suma=0,sumb=0;
    scanf("%d %d",&n,&m);

    if(n<m||n==0)
        printf("%d",m*3);
    else if(m==0)
        printf("%d",n*2);
    else
    {

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
        }
        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
            if(sumb%2==0)
                sumb=sumb+3;
        }
        while(sumb>=suma)
        {
            suma=suma+2;
            if(suma>sumb)
            {
                suma=suma-2;
                break;
            }

            else
                sumb=sumb-6;
        }
        s1=max(suma,sumb);
        suma=0;
        sumb=0;

        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
        }

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
            if(suma%3==0)
                suma=suma+2;
        }
        j=sumb/6;
        while(suma>=sumb&&j>=0)
        {

            sumb=sumb+3;
            if(sumb>suma)
            {
                sumb=sumb-3;
                break;
            }
            else
                suma=suma-2;

            j--;
        }
        s2=max(suma,sumb);

        s=min(s1,s2);
        printf("%d\n",s);
    }

    return 0;
}

int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}

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

#include<stdio.h>
int min(int a,int b);
int max(int a,int b);
int main()
{
    int r,i,j,n,m;
    int s,s1,s2,suma=0,sumb=0;
    scanf("%d %d",&n,&m);

    if(n<m||n==0)
        printf("%d",m*3);
    else if(m==0)
        printf("%d",n*2);
    else
    {

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
        }
        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
            if(sumb%2==0)
                sumb=sumb+3;
           // printf("%d= %d\n",i,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        //j=suma/6-1;
        while(sumb>=suma)
        {
            suma=suma+2;
            if(suma>sumb)
            {
                suma=suma-2;
                break;
            }

            else
                sumb=sumb-6;

            //j--;
            //printf("\tsuma= %d\tsumb=%d\n",suma,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s1=max(suma,sumb);
        suma=0;
        sumb=0;

        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
        }

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
            if(suma%3==0)
                suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        j=sumb/6;
        while(suma>=sumb&&j>=0)
        {

            sumb=sumb+3;
            if(sumb>suma)
            {
                sumb=sumb-3;
                break;
            }
            else
                suma=suma-2;

            j--;
           // printf("j= %d\tsuma= %d\tsumb=%d\n",j,suma,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s2=max(suma,sumb);

        s=min(s1,s2);
        printf("%d\n",s);
}

    return 0;
}

int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}

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

/*
By Tianyi Chen
*/
#include<stdio.h>
int n,m,ans;
int main() {
 scanf("%d%d",&n,&m);
 while(++ans)
  if(n+m<=ans/2+ans/3-ans/6)break;
 if(ans<2*n)ans=2*n;
 if(ans<3*m)ans=3*m;
 printf("%d\n",ans);
}

#include<stdio.h>

int small(int,int);
int big(int,int);

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int maxn=n*2;
	int maxm=m*3;
	int count=0;

	while(small(maxn,maxm)/6-count)
	{
		if(maxn+2 < maxm+3)
			maxn+=2;
		else
			maxm+=3;
		count++;
	}

	printf("%d\n",big(maxn,maxm));
	return 0;
}

int small(int a,int b)
{
	if(a<b)
		return a;
	else
		return b;
}

int big(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}

#include<stdio.h>
typedef unsigned u;
u max(u a,u b){return a>b?a:b;}
u min(u a,u b){return a>b?b:a;}
int main()
{
	u w,x,y,z;
	scanf("%u%u",&x,&y);
	x*=2;y*=3;
	for(w=z=0;(w+=6)<=min(x,y);)
	{
		if(x+2>y+3)y+=3;
		else x+=2;
	}
	printf("%u\n",max(x,y));
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m;
    scanf("%i %i",&n,&m);

    int hm = m*3,hn = n*2,count = 1,plus1 = 0,plus2 = 0;

    while(hn > 0 || hm > 0)
    {
        if(count%2 == 0 && count%3 == 0)
        {
            if(hm > hn)
            {
                hm-=3;
            }
            else
            {
                hn-=2;
            }
        }
        else if(count%2 == 0)
        {
            hn-=2;
        }
        else if(count%3 == 0)
        {
            hm-=3;
        }
        count++;
    }

        printf("%i",count-1);

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef long long int LL;

#define din(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define llin(n) scanf("%lld",&n)
#define llout(n) printf("%lld\n",n)
#define strin(n) scanf(" %s",n)
#define strout(n) printf("%s\n",n)
#define power(a, b) po(a, b)

int mod=1000000007;

long long po(long long x, long long y)
{
	long long pro=1;
	while(y>0)
	{
		if(y&1 != 0)
			pro=((pro%mod)*(x%mod))%mod;
		x=(x*x)%mod;
		y=y>>1;
	}
	return pro%mod;
}

int main(void)
{
	long long two,three;
	long long i;

	llin(two);
	llin(three);

	// NEWER VERSION
	for(i=2;;i++)
	{
		if(i%6==0)
		{
			if(three == 0)
				two--;
			else if(two == 0)
				three--;
			else if(two > 0 && three > 0)
			{
				if(two > three)
					two--;
				else
					three--;
			}
		}
		else if(i%2 == 0 && two > 0)
			two--;
		else if(i%3 == 0 && three > 0)
			three--;

		if(two==0 && three==0)
			break;
	}
	llout(i);
	return(0);
}

#include <stdio.h>
#include <stdlib.h>

char vet[210];

int max (int a, int b, int res) {
	if (res > a && res > b)
		return res;
	return a > b ? a : b;

}

int main () {

	int n, m;
	int i, k;
	int res = 0;

	scanf("%d %d", &n, &m);

	for (i = 2, k = 3; n > 0 || m > 0;) {

		if (!n)
			i = -1;
		if (!m)
			k = -1;

		while (i + 2 <= k && n) {
			if (n)
				n--;

			res = max(i, k, res);
			if (!n)
				i = -1;
			if (i)
				i += 2;
		}

		if (i != k) {
			if (n)
				n--;
			if (m)
				m--;

			res = max(i, k, res);
			if (!n)
				i = -1;
			if (!m)
				k = -1;
			if (i)
				i += 2;
			if (k)
				k += 3;
		} else {
			if (2 * n <= 3 * m) {
				if (m)
					m--;

				res = max(i, k, res);
				if (!m)
					k = -1;
				if (k)
					k += 3;
				if (i)
					i += 2;
			} else {
				if (n)
					n--;

				res = max(i, k, res);
				if (!n)
					i = -1;
				if (i)
					i += 2;
				if (k)
					k += 3;
			}
		}
	}

	printf("%d\n", res);

	return 0;

}

#include<stdio.h>
int main()
{
	int n,m,i;
	scanf("%d%d",&n,&m);
	for(i=1;;i++)
	{
		if(n<=i/2 && m<=i/3 && n+m<=i/2+i/3-i/6)
			break;
	}
	printf("%d\n",i);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 205
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

long long a, b;

bool F(long long h){
    if ((a * 2) > h) return false;
    if ((b * 3) > h) return false;

    long long x = (h / 2) + (h / 3) - (h / 6);
    return (x >= (a + b));
}

int main(){
    int i, j, k;
    long long low, high, mid, res;

    while (scanf("%lld %lld", &a, &b) != EOF){
        low = 2, high = 1LL << 60;
        while ((low + 1) < high){
            mid = (low + high) >> 1;
            if (F(mid)) high = mid;
            else low = mid;
        }

        if (F(low)) res = low;
        else res = high;
        printf("%lld\n", res);
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

int main(){
	int n, m, i, comm,d2,d3;
	scanf("%d %d",&n,&m);
	i=1;
	comm=0;
	while((n+m)>comm){
		d2=1;d3=0;
		if(i&1)
			d2=0;
		if((i/3)*3==i)
			d3=1;
		if(d3 && d2)
			comm++;
		else if(d2 && n)
			n--;
		else if(d3 && m)
			m--;
		i++;
	}
	printf("%d\n",i-1);
	return 0;
}

#include <stdio.h>

#define N_MAX         1000000
#define M_MAX         1000000

int mod(int divisor, int dividend)
{
	int remainder;

	if(dividend == 0)
		return 0;

	remainder = divisor - (int)(divisor/dividend)*dividend;

	return remainder;
}

int belongs_to_two(int i)
{
	if(mod(i,2) == 0)
		return 1;
	else
		return 0;
}

int belongs_to_three(int i)
{
	if(mod(i,3) == 0)
		return 1;
	else
		return 0;
}

int GetAnswer(int n, int m)
{
	int i,j,k;
	int answer = 0;
	int b_two, b_three;

	k = 0;
	i = 1;
	j = 0;

	while( n + m > 0 ){
		//printf("i = %d ... n = %d ... m = %d\n",i,n,m);
		b_two = belongs_to_two(i);
		b_three = belongs_to_three(i);
		//printf("b_two = %d ... b_three = %d\n",b_two,b_three);
		if((b_two == 1) && (b_three == 0)){
			if(n > 0){
				n--;
			}
		}
		if((b_two == 0) && (b_three == 1)){
			if(m > 0){
				m--;
			}
		}
		if((b_two == 1) && (b_three == 1)){
			// Reduce greater of n,m
			if((n > 0) && (m > 0)){
				if(n > m){
					n--;
				}
				else if(m > n){
					m--;
				}
				else{
					m--;
				}
			}
			else if(n > 0){
				n--;
			}
			else if(m > 0){
				m--;
			}
		}
		i++;

	}

	return i-1;
}

int main()
{
	int n, m;
	int answer = 0;

	/* handle the program options */
	//freopen("C:/Users/Subh/Desktop/Work/Coding/C_code/test42.txt","rt",stdin);

	scanf("%d %d",&n,&m);

	/* The code of your application goes here */
	answer = GetAnswer(n, m);

	printf("%d\n",answer);

	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m;

    scanf("%d %d", &n, &m);

    int ans = 0;

    int temp;
    int cnt6, cnt3, slot;
    int top = 0;
    int i = 0;
    while (n > 0 || m > 0)
    {
        i++;
        switch (i%6) {
            case 0:
                if(m>0){
                    if (n>m) n--;
                    else m--;
                }
                else n--;
                break;
            case 2:
                n--;
                break;
            case 3:
                m--;
                break;
            case 4:
                n--;
                break;
        }
    }
    printf("%d\n", i);

    return 0;
}

#include<stdio.h>

int fun(int a,int b)
{
    if(a<b)
    return b;
    else
    return a;
}

int factors(int a)
{
    return (a/2+a/3-a/6);
}

int main()
{
   int n,m;
   scanf("%d %d",&n,&m);
   int x=2*n,y=3*m;
   int max=fun(x,y);
   int count=factors(max);
   while(count<n+m){
       if((max+1)%2==0||(max+1)%3==0)
       {
           count=factors(max+1);
           max++;
       }
       else
       {
           count=factors(max+2);
           max+=2;
       }
   }
   printf("%d",max);
}

#include<stdio.h>

#define N 101

int set1[10000001]={0};
int set2[10000001]={0};

int main()
{
	int left, right, i, count = 1, check = 0;

	scanf("%d%d", &left, &right);

	for(i = 2; i <= 1e7; i+=2)
		set1[count++] = i;
	count = 1;
	for(i = 3; i <= 1e7; i+=3)
		set2[count++] = i;

	int temp, left_use = 0, right_use = 0;

	if((set1[left]/6) >= (set2[right]/6))
		temp = set2[right]/6;

	else if((set1[left]/6) < (set2[right]/6))
		temp = set1[left]/6;

	for(i = 0; i < temp; i++)
	{
		if(set1[left+1] > set2[right+1])
		{
			right += 1;
			right_use = 1;
		}
		else if(set1[left+1] <= set2[right+1])
		{
			left += 1;
			left_use = 1;
		}
		if((left_use == 1) && (set1[left]%6 == 0))
		{
			if(set2[right] > set1[left])
				temp++;

			left_use = 0;
		}
		else if((right_use == 1) && (set2[right]%6 == 0))
		{
			if(set1[left] > set2[right])
				temp++;

			right_use = 0;
		}
		if(set1[left] == set2[right])
			temp++;
	}
	if(set1[left] > set2[right])
		printf("%d", set1[left]);
	else if(set1[left] < set2[right])
		printf("%d", set2[right]);

    return 0;
}

#include <stdio.h>

int main(){
	long long n, m, hn, hm, tester = 6, r;

	scanf("%lld %lld", &n, &m);

	hn = 6 * ((n - 1)/ 2) + 2 + 2 * ((n - 1) % 2);
	hm = 3 * (2 * m - 1);

	while (tester < hn || tester < hm){
		if (hn > hm){
			r = (hn / 2) % 3;

			if (r == 1)
				hn -= 4;
			else if (r == 2)
				hn -= 2;

			if (tester > hn)
				hn = tester;
		}
		else{
			hm -= 6;

			if (tester > hm)
				hm = tester;
		}

		tester += 6;
	}

	if (hn > hm)
		printf("%lld", hn);
	else
		printf("%lld", hm);

	return 0;
}

#include<stdio.h>
int min(int x,int y)
{
	return x>y?y:x;
}

int max(int x,int y)
{
	return x>y?x:y;
}

int main()
{
	int n,m;
	int i,k,delay;
	while( (scanf("%d %d",&n,&m)) == 2)
	{
		delay=0;
		k=min(2*n,3*m);
		for(i=6; i<=k; i+=6)
			if(k >= i) delay++;
		if(delay==0) printf("%d\n",max(2*n,3*m));
		else printf("%d\n",min(2*n+2,3*m+3));
	}
	return 0;
}

#include <stdio.h>

int n,m;

int check(int a)
{
	if((a/2<n) || (a/3<m) || (a/2+a/3-a/6<m+n))
	return 0;
	return 1;
}

int main()
{
	int l=0,r=1000000,mid;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		l=0; r=1000000;
		while(l+1<r)
		{
			mid=(l+r)/2;
			if(check(mid)==1)
			{
				r=mid;
			}
			else
			{
				l=mid;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

#include<stdio.h>
int min(int a,int b)
{
	if(a<b)
	return a;
	return b;
}
int max(int a,int b)
{
	if(a>b)
	return a;
	return b;
}
int main()
{
	int ans=0,a,b,k;
	scanf("%d %d",&a,&b);
	int c=a/3;
	int d=b/2;
	k=min(c,d);
	int ans1=a*2+k*2;
	int ans2=b*3+k*3;
	int ans3=max(ans1,b*3);
	int ans4=max(ans2,a*2);
	ans=min(ans3,ans4);
	printf("%d",ans);
	return 0;

}

#include<stdio.h>
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);

    if(m>n)
        printf("%d",m*3);
    else
        printf("%d",2*(n+m/2));
    return 0;
}

#include<stdio.h>
int min(int a,int b);
int max(int a,int b);
int main()
{
    int r,i,j,n,m;
    int s,s1,s2,suma=0,sumb=0;
    scanf("%d %d",&n,&m);

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
        }
        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
            if(sumb%2==0)
                sumb=sumb+3;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s1=max(suma,sumb);
        suma=0;
        sumb=0;

        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
        }

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
            if(suma%3==0)
                suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s2=max(suma,sumb);

        s=min(s1,s2);
        printf("%d\n",s);

    return 0;
}

int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}

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

#include<stdio.h>
int min(int a,int b);
int max(int a,int b);
int main()
{
    int r,i,j,n,m;
    int s,s1,s2,suma=0,sumb=0;
    scanf("%d %d",&n,&m);

    if(n<m||n==0)
        printf("%d",m*3);
    else if(m==0)
        printf("%d",n*2);
    else
    {

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
        }
        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
            if(sumb%2==0)
                sumb=sumb+3;
           // printf("%d= %d\n",i,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        while(sumb>=suma)
        {
            sumb=sumb-6;
            suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s1=max(suma,sumb);
        suma=0;
        sumb=0;

        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
        }

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
            if(suma%3==0)
                suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        while(suma>=sumb)
        {
            suma=suma-2;
            sumb=sumb+3;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s2=max(suma,sumb);

        s=min(s1,s2);
        printf("%d\n",s);
}

    return 0;
}

int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}

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

#include<stdio.h>
int main()
{
    int r,i,j,n,m;
    int suma=0,sumb=0;
    scanf("%d %d",&n,&m);

    if(n>m)
        r=n;
    else
        r=m;

    for(i=1;i<=r;i++)
    {
        if(i<=n)
        {
            suma=suma+2;
            if(suma==sumb)
                suma=suma+2;
        }

        if(i<=m)
        sumb=sumb+3;

    }

    if(suma>sumb)
        printf("%d",suma);
    else
        printf("%d",sumb);
    return 0;
}

#include<stdio.h>
int min(int a,int b);
int max(int a,int b);
int main()
{
    int r,i,j,n,m;
    int s,s1,s2,suma=0,sumb=0;
    scanf("%d %d",&n,&m);

    if(n<m||n==0)
        printf("%d",m*3);
    else if(m==0)
        printf("%d",n*2);
    else
    {

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
        }
        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
            if(sumb%2==0)
                sumb=sumb+3;
           // printf("%d= %d\n",i,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        while(sumb>=suma)
        {
            sumb=sumb-6;
            suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s1=max(suma,sumb);
        suma=0;
        sumb=0;

        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
        }

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
            if(suma%3==0)
                suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        j=sumb/6;
        while(suma>=sumb&&j>=0)
        {
            suma=suma-2;
            sumb=sumb+3;
            j--;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s2=max(suma,sumb);

        s=min(s1,s2);
        printf("%d\n",s);
}

    return 0;
}

int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}

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

#include<stdio.h>
int min(int a,int b);
int max(int a,int b);
int main()
{
    int r,i,j,n,m;
    int s,s1,s2,suma=0,sumb=0;
    scanf("%d %d",&n,&m);

    if(n<m||n==0)
        printf("%d",m*3);
    else if(m==0)
        printf("%d",n*2);
    else
    {

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
        }
        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
            if(sumb%2==0)
                sumb=sumb+3;
           // printf("%d= %d\n",i,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        //j=suma/6-1;
        while(sumb>=suma)
        {
            suma=suma+2;
            if(suma>sumb)
            {
                suma=suma-2;
                break;
            }

            else
                sumb=sumb-6;

            //j--;
            //printf("\tsuma= %d\tsumb=%d\n",suma,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s1=max(suma,sumb);
        suma=0;
        sumb=0;

        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
        }

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
            if(suma%3==0)
                suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        j=sumb/6;
        while(suma>=sumb&&j>=0)
        {

            sumb=sumb+3;
            if(sumb>suma)
            {
                sumb=sumb-3;
                break;
            }
            else
                suma=suma-2;

            j--;
           // printf("j= %d\tsuma= %d\tsumb=%d\n",j,suma,sumb);
        }
        printf("%d\n",suma);
        printf("%d\n",sumb);
        s2=max(suma,sumb);

        s=min(s1,s2);
        printf("%d\n",s);
}

    return 0;
}

int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}

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

#include<stdio.h>
int min(int a,int b);
int max(int a,int b);
int main()
{
    int r,i,j,n,m;
    int s,s1,s2,suma=0,sumb=0;
    scanf("%d %d",&n,&m);

    if(n==0)
        printf("%d",m*3);
    else if(m==0)
        printf("%d",n*2);
    else
    {

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
        }
        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
            if(sumb%2==0)
                sumb=sumb+3;
           // printf("%d= %d\n",i,sumb);
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        while(sumb>=suma)
        {
            sumb=sumb-6;
            suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s1=max(suma,sumb);
        suma=0;
        sumb=0;

        for(i=1;i<=m;i++)
        {
            sumb=sumb+3;
        }

        for(i=1;i<=n;i++)
        {
            suma=suma+2;
            if(suma%3==0)
                suma=suma+2;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        while(suma>=sumb)
        {
            suma=suma-2;
            sumb=sumb+3;
        }
        //printf("%d\n",suma);
        //printf("%d\n",sumb);
        s2=max(suma,sumb);

        s=min(s1,s2);
        printf("%d\n",s);
}

    return 0;
}

int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}

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

#include<stdio.h>

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int max=m*3;
	int count;
	if(max>n*2)
		count=(n*2)/6;
	else
		count=max/6;

	if((n+count)*2>max)
		max=(n+count)*2;

	printf("%d\n",max);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef long long int LL;

#define din(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define llin(n) scanf("%lld",&n)
#define llout(n) printf("%lld\n",n)
#define strin(n) scanf(" %s",n)
#define strout(n) printf("%s\n",n)
#define power(a, b) po(a, b)

int mod=1000000007;

long long po(long long x, long long y)
{
	long long pro=1;
	while(y>0)
	{
		if(y&1 != 0)
			pro=((pro%mod)*(x%mod))%mod;
		x=(x*x)%mod;
		y=y>>1;
	}
	return pro%mod;
}

int main(void)
{
	long long two,three;
	long long i;

	llin(two);
	llin(three);

	// NEWER VERSION
	for(i=2;;i++)
	{
		if(i%6==0)
		{
			if(three == 0)
				two--;
			else if(two == 0)
				three--;
			else if(two > 0 && three > 0)
			{
				if(two >= three)
					three--;
				else
					two--;
			}
		}
		else if(i%2 == 0 && two > 0)
			two--;
		else if(i%3 == 0 && three > 0)
			three--;

		if(two==0 && three==0)
			break;
	}
	llout(i);
	return(0);
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef long long int LL;

#define din(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define llin(n) scanf("%lld",&n)
#define llout(n) printf("%lld\n",n)
#define strin(n) scanf(" %s",n)
#define strout(n) printf("%s\n",n)
#define power(a, b) po(a, b)

int mod=1000000007;

long long po(long long x, long long y)
{
	long long pro=1;
	while(y>0)
	{
		if(y&1 != 0)
			pro=((pro%mod)*(x%mod))%mod;
		x=(x*x)%mod;
		y=y>>1;
	}
	return pro%mod;
}

int main(void)
{
	long long two,three;
	llin(two);
	llin(three);
	long long i=1;
	long long c2=0;
	long long c3=0;
	while(c2<two)
	{
		if(i%2==0 && i%3!=0)
			c2++;
		else if(i%3==0 && i%2!=0 && c3<three)
			c3++;
		else if(i%3==0 && i%2==0 && c2<two)
			c2++;
		i++;
	}
	while(c3<three)
	{
		if(i%3==0)
			c3++;
		i++;
	}
	long long ans1=i-1;
	i=1;
	c2=0;
	c3=0;
	while(c3<three)
	{
		if(i%2==0 && i%3!=0 && c2<two)
			c2++;
		else if(i%3==0 && i%2!=0 && c3<three)
			c3++;
		else if(i%3==0 && i%2==0 && c3<three)
			c3++;
		i++;
	}
	while(c2<two)
	{
		if(i%2==0)
			c2++;
		i++;
	}
	long long ans2=i-1;
	if(ans1>ans2)
		printf("%lld\n", ans2);
	else
		printf("%lld\n", ans1);
	return(0);
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef long long int LL;

#define din(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define llin(n) scanf("%lld",&n)
#define llout(n) printf("%lld\n",n)
#define strin(n) scanf(" %s",n)
#define strout(n) printf("%s\n",n)
#define power(a, b) po(a, b)

int mod=1000000007;

long long po(long long x, long long y)
{
	long long pro=1;
	while(y>0)
	{
		if(y&1 != 0)
			pro=((pro%mod)*(x%mod))%mod;
		x=(x*x)%mod;
		y=y>>1;
	}
	return pro%mod;
}

int main(void)
{
	long long two,three;
	llin(two);
	llin(three);
	long long i=1;
	long long c2=0;
	long long c3=0;
	while(c2<two)
	{
		if(i%2==0 && i%3!=0 && c2<two)
			c2++;
		else if(i%3==0 && i%2!=0 && c3<three)
			c3++;
		else if(i%3==0 && i%2==0)
		{
			if(c2<two)
				c2++;
			else
				break;
		}
		i++;
	}
	while(c3<three)
	{
		if(i%3==0)
			c3++;
		i++;
	}
	long long ans1=i-1;
	i=1;
	c2=0;
	c3=0;
	while(c3<three)
	{
		if(i%2==0 && i%3!=0 && c2<two)
			c2++;
		else if(i%3==0 && i%2!=0 && c3<three)
			c3++;
		else if(i%3==0 && i%2==0)
		{
			if(c3<three)
				c3++;
			else
				break;
		}
		i++;
	}
	while(c2<two)
	{
		if(i%2==0)
			c2++;
		i++;
	}
	long long ans2=i-1;
	if(ans1>ans2)
		printf("%lld\n", ans2);
	else
		printf("%lld\n", ans1);
	return(0);
}

#include <stdio.h>
#include <stdlib.h>

char vet[210];

int max (int a, int b, int res) {
	if (res > a && res > b)
		return res;
	return a > b ? a : b;

}

int main () {

	int n, m;
	int i, k;
	int res = 0;

	scanf("%d %d", &n, &m);

	for (i = 2, k = 3; n > 0 || m > 0;) {

		while (i + 2 <= k && n) {
			if (n)
				n--;

			res = max(i, k, res);
			if (!n)
				i = -1;
			if (i)
				i += 2;
		}

		if (i != k) {
			if (n)
				n--;
			if (m)
				m--;

			res = max(i, k, res);
			if (!n)
				i = -1;
			if (!m)
				k = -1;
			if (i)
				i += 2;
			if (k)
				k += 3;
		} else {
			if (2 * n <= 3 * m) {
				if (m)
					m--;

				res = max(i, k, res);
				if (!m)
					k = -1;
				if (k)
					k += 3;
				if (i)
					i += 2;
			} else {
				if (n)
					n--;

				res = max(i, k, res);
				if (!n)
					i = -1;
				if (i)
					i += 2;
				if (k)
					k += 3;
			}
		}
	}

	printf("%d\n", res);

	return 0;

}

#include<stdio.h>
int main()
{
	int ans=0,n,m;
	scanf("%d%d",&n,&m);
	if(2*n==3*m)
		ans=2*n+2*((2*n)/6);
	else if(2*n>3*m)
		ans=2*n;
	else if(3*m>2*n)
		ans=3*m;
	printf("%d\n",ans);
	return 0;
}

#include<stdio.h>
int min(int a,int b)
{
	return a<b?a:b;
}
int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	int i,max_h3,max_h2,clashes,ans=0,n,m;
	scanf("%d%d",&n,&m);
	max_h3=3*m;
	max_h2=2*n;
	if(2*n>3*m)
	{
		clashes=(3*m)/6;
		for(i=1;i<=clashes;i++)
		{
			if(max_h3<max_h2)
				max_h3+=3;
			else
				max_h2+=2;
		}
		ans=max(max_h3,max_h2);
	}
	else
	{
		clashes=(2*n)/6;
		for(i=1;i<=clashes;i++)
                {
                        if(max_h3<max_h2)
                                max_h3+=3;
                        else
                                max_h2+=2;
                }
                ans=max(max_h3,max_h2);
	}
	printf("%d\n",ans);
	return 0;
}

#include <stdio.h>

#define N_MAX         1000000
#define M_MAX         1000000

int mod(int divisor, int dividend)
{
	int remainder;

	if(dividend == 0)
		return 0;

	remainder = divisor - (int)(divisor/dividend)*dividend;

	return remainder;
}

int belongs_to_two(int i)
{
	if(mod(i,2) == 0)
		return 1;
	else
		return 0;
}

int belongs_to_three(int i)
{
	if(mod(i,3) == 0)
		return 1;
	else
		return 0;
}

int GetAnswer(int n, int m)
{
	int i,j,k;
	int answer = 0;
	int b_two, b_three;

	k = 0;
	i = 1;
	j = 0;

	while( n + m > 0 ){
		printf("i = %d ... n = %d ... m = %d\n",i,n,m);
		b_two = belongs_to_two(i);
		b_three = belongs_to_three(i);
		printf("b_two = %d ... b_three = %d\n",b_two,b_three);
		if((b_two == 1) && (b_three == 0)){
			if(n > 0){
				n--;
			}
		}
		if((b_two == 0) && (b_three == 1)){
			if(m > 0){
				m--;
			}
		}
		if((b_two == 1) && (b_three == 1)){
			if(m > 0){
				m--;
			}
			else{
				n--;
			}
		}
		i++;

	}

	return i-1;
}

int main()
{
	int n, m;
	int answer = 0;

	/* handle the program options */
	//freopen("C:/Users/Subh/Desktop/Work/Coding/C_code/test42.txt","rt",stdin);

	scanf("%d %d",&n,&m);

	/* The code of your application goes here */
	answer = GetAnswer(n, m);

	printf("Answer: %d\n",answer);

	return 0;
}

#include <stdio.h>

#define N_MAX         1000000
#define M_MAX         1000000

int mod(int divisor, int dividend)
{
	int remainder;

	if(dividend == 0)
		return 0;

	remainder = divisor - (int)(divisor/dividend)*dividend;

	return remainder;
}

int belongs_to_two(int i)
{
	if(mod(i,2) == 0)
		return 1;
	else
		return 0;
}

int belongs_to_three(int i)
{
	if(mod(i,3) == 0)
		return 1;
	else
		return 0;
}

int GetAnswer(int n, int m)
{
	int i,j,k;
	int answer = 0;
	int b_two, b_three;

	k = 0;
	i = 1;
	j = 0;

	while( n + m > 0 ){
		//printf("i = %d ... n = %d ... m = %d\n",i,n,m);
		b_two = belongs_to_two(i);
		b_three = belongs_to_three(i);
		//printf("b_two = %d ... b_three = %d\n",b_two,b_three);
		if((b_two == 1) && (b_three == 0)){
			if(n > 0){
				n--;
			}
		}
		if((b_two == 0) && (b_three == 1)){
			if(m > 0){
				m--;
			}
		}
		if((b_two == 1) && (b_three == 1)){
			if(m > 0){
				m--;
			}
			else{
				n--;
			}
		}
		i++;

	}

	return i-1;
}

int main()
{
	int n, m;
	int answer = 0;

	/* handle the program options */
	//freopen("C:/Users/Subh/Desktop/Work/Coding/C_code/test42.txt","rt",stdin);

	scanf("%d %d",&n,&m);

	/* The code of your application goes here */
	answer = GetAnswer(n, m);

	printf("%d\n",answer);

	return 0;
}

#include <stdio.h>

int main() {

    int n2, n3;

    int res;

    scanf("%u%u", &n2, &n3);

    res = n3 * 3;
    n2 -= n3;
    if (n2 > 0)
        res += n2 * 2;

    printf("%u", res);

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m;

    scanf("%d %d", &n, &m);

    int ans = 0;

    int temp;
    int cnt6, cnt3, slot;
    int top = 0;
    while (n > 0 || m > 0)
    {
        if (n != 0) {
            temp = 2 * n;

            n = 0;
            if (m > 0) {
                cnt3 = (temp-top)/3;
                cnt6 = (temp - top)/6;

                //printf("cnt6 : %d\n", cnt6);
                if (m >= cnt3) {
                    //printf("t1\n");
                    n+=cnt6;
                    m-=cnt3;
                    top += cnt3*3;
                } else {
                    //printf("t2\n");
                    n += m;
                    m = 0;
                    top += m*3;
                }
            }
            ans+=temp;
        } else {
            //printf("%d %d %d\n", n, m, top);
            top+=m*3;
            m=0;

        }

    }
    if (top > ans) {
        printf("%d\n", top);
    } else
        printf("%d\n", ans);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m;

    scanf("%d %d", &n, &m);

    int ans = 0;

    int temp;
    int cnt6, cnt3, slot;
    int top = 0;
    int i = 0;

    while (n > 0 || m > 0)
    {
        i++;
        switch (i%6) {
            case 0:
                if(m>0 && m != 1) m--;
                else n--;
                break;
            case 2:
                n--;
                break;
            case 3:
                m--;
                break;
            case 4:
                n--;
                break;
        }
    }
    printf("%d\n", i);

    return 0;
}

#include<stdio.h>

int fun(int a,int b)
{
    if(a<b)
    return b;
    else
    return a;
}

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int i=1,j=1,max,h1,h2;
    int flag1=n,flag2=m;
    while(n>0||m>0)
    {
        if(n>0){
           h1=2*i;
            if((2*(i+1))%6==0&&i<=flag2)
            i+=2;
            else
            i++;
            n--;
        }
        if(m>0){
            h2=3*j;
            j++;
            m--;
        }
        if(flag1==0||i==flag1)
        max=h2;
        else if(flag2==0||j==flag2)
        max=h1;
        else
        max=fun(h1,h2);
    }
    printf("%d",max);
}

#include <stdio.h>

int main() {
    int a, b, d, c, x;
    scanf("%d %d", &a, &b);
    if (a > b) {
	c = a * 2;
	if (b != 0) {
	    for (x = 0; x < a; x++) {
		d = x * 3;
		if (d > c) {
		    printf ("%d", d);
	    	    break;
		}
	    }
	    if (d < c)
		printf ("%d", c);
	    if (d = c)
		printf ("%d", c+2);
	} else {
	    printf ("%d", c);
	}
    } else if (b > a) {
	d = b * 3;
	if (a != 0) {
	    for (x = 0; x < b; x++) {
		c = x * 2;
		if (c > d) {
		    printf ("%d", c);
		}
	    }
	    if (c < d)
		printf ("%d", d);
	} else {
	    printf ("%d", d);
	}
    } else
	printf ("%d", b*3);
    return 0;
}

#include <stdio.h>

int main() {
    int a, b, d, c, x;
    scanf("%d %d", &a, &b);
    if (a > b) {
	c = a * 2;
	if (b != 0) {
	    for (x = 0; x < a; x++) {
		d = x * 3;
		if (d > c) {
		    printf ("%d", d);
	    	    break;
		}
	    }
	    if (d < c)
		printf ("%d", c);
	    if (d == c) {
		printf ("%d", c+2);
	    }
	} else {
	    printf ("%d", c);
	}
    } else if (b > a) {
	d = b * 3;
	if (a != 0) {
	    for (x = 0; x < b; x++) {
		c = x * 2;
		if (c > d) {
		    printf ("%d", c);
		}
	    }
	    if (c < d)
		printf ("%d", d);
	} else {
	    printf ("%d", d);
	}
    } else
	printf ("%d", b*3);
    return 0;
}

#include<stdio.h>

#define N 101

int set1[1000001]={0};
int set2[1000001]={0};

int main()
{
	int left, right, i, count = 1, check = 0;

	scanf("%d%d", &left, &right);

	for(i = 2; i <= 2000000; i++)
		if(i%2 == 0)
			set1[count++] = i;
	count = 1;
	for(i = 3; i <= 3000000; i++)
		if(i%3 == 0)
			set2[count++] = i;

	int temp, left_use = 0, right_use = 0;

	if((set1[left]/6) >= (set2[right]/6))
	{
		temp = set2[right]/6;
		check = 0;
	}
	else if((set1[left]/6) < (set2[right]/6))
	{
		temp = set1[left]/6;
		check = 1;
	}

	for(i = 0; i < temp; i++)
	{
		if(set1[left+1] >= set2[right+1])
		{
			right += 1;
			right_use = 1;
		}
		else if(set1[left+1] < set2[right+1])
		{
			left += 1;
			left_use = 1;
		}
		if((check == 1) && (left_use == 1))
		{
			if(set1[left]%6 == 0)
				temp++;
		}
		else if((check == 0) && (right_use == 1))
		{
			if(set2[right]%6 == 0)
				temp++;
		}
	}
	if(set1[left] > set2[right])
		printf("%d", set1[left]);
	else if(set1[left] < set2[right])
		printf("%d", set2[right]);

    return 0;
}

#include<stdio.h>

#define N 101

int set1[1000001]={0};
int set2[1000001]={0};

int main()
{
	int left, right, i, count = 1, check = 0;

	scanf("%d%d", &left, &right);

	for(i = 2; i <= 2000000; i++)
		if(i%2 == 0)
			set1[count++] = i;
	count = 1;
	for(i = 3; i <= 3000000; i++)
		if(i%3 == 0)
			set2[count++] = i;

	int temp;

	if((set1[left]/6) >= (set2[right]/6))
	{
		temp = set2[right]/6;
		check = 0;
	}
	else if((set1[left]/6) < (set2[right]/6))
	{
		temp = set1[left]/6;
		check = 1;
	}

	for(i = 0; i < temp; i++)
	{
		if(set1[left+1] >= set2[right+1])
			right += 1;
		else if(set1[left+1] < set2[right+1])
			left += 1;
		if(check == 1)
		{
			if(set1[left]%6 == 0)
				temp++;
		}
		else if(check == 0)
		{
			if(set2[right]%6 == 0)
				temp++;
		}
	}
	if(set1[left] > set2[right])
		printf("%d", set1[left]);
	else if(set1[left] < set2[right])
		printf("%d", set2[right]);

    return 0;
}

#include <stdio.h>

int main(){
	long long n, m, hn, hm, tester = 6, r;

	scanf("%lld %lld", &n, &m);

	hn = 6 * ((n - 1)/ 2) + 2 + 2 * ((n - 1) % 2);
	hm = 3 * (2 * m - 1);

	while (tester < hn || tester < hm){
		printf("%lld %lld\n", hn, hm);

		if (hn > hm){
			r = (hn / 2) % 3;

			if (r == 1)
				hn -= 4;
			else if (r == 2)
				hn -= 2;

			if (tester > hn)
				hn = tester;
		}
		else{
			hm -= 6;

			if (tester > hm)
				hm = tester;
		}

		tester += 6;
	}
		printf("%lld %lld\n", hn, hm);

	if (hn > hm)
		printf("%lld", hn);
	else
		printf("%lld", hm);

	return 0;
}

#include <stdio.h>

int main(){
	int n, m, hn, hm, tester = 6, r;

	scanf("%d %d", &n, &m);

	hn = 6 * ((n - 1)/ 2) + 2 + 2 * ((n - 1) % 2);
	hm = 3 * (2 * m - 1);

	while (tester < hn || tester < hm){
		if (hn > hm){
			r = (hn / 2) % 3;

			if (r == 1)
				hn -= 4;
			else if (r == 2)
				hn -= 6;

			if (tester > hn)
				hn = tester;
		}
		else{
			hm -= 6;

			if (tester > hm)
				hm = tester;
		}

		tester += 6;
	}

	if (hn > hm)
		printf("%d", hn);
	else
		printf("%d", hm);

	return 0;
}

#include <stdio.h>

int main(){
	long long n, m, hn, hm, tester = 6, r;

	scanf("%lld %lld", &n, &m);

	hn = 6 * ((n - 1)/ 2) + 2 + 2 * ((n - 1) % 2);
	hm = 3 * (2 * m - 1);

	while (tester < hn || tester < hm){
		if (hn > hm){
			r = (hn / 2) % 3;

			if (r == 1)
				hn -= 4;
			else if (r == 2)
				hn -= 6;

			if (tester > hn)
				hn = tester;
		}
		else{
			hm -= 6;

			if (tester > hm)
				hm = tester;
		}

		tester += 6;
	}

	if (hn > hm)
		printf("%lld", hn);
	else
		printf("%lld", hm);

	return 0;
}