int main()
{
	char st[1000],temp;
	scanf("%s",st);
	int t,len=strlen(st);
	int i,x=0;
	for(t=0;t<len;t++)if(st[t]>='a'&&st[t]<='z')st[t]=st[t]-'a'+'A';
	for(t=0;x<len;t++){
		temp=st[x];
		for(i=0;;i++){
			if(st[x+i]!=st[x+i+1])break;
		}
		printf("(%c,%d)",st[x],i+1);
		x=x+i+1;
	}
	return 0;
}


main()
{
      int i,count=0,j,l;
      char string[1000];
      scanf("%s",string);
      l=strlen(string);
      for(i=0;i<l;i++)
      {
            if(string[i]>='a'&&string[i]<='z')
             string[i]=string[i]-'a'+'A';
      }
      char s;
      s = string[0];
      for(i=0;i<l;i++)
      {
          if(string[i]==s)
             count++;
          else
          {
             printf("(%c,%d)",s,count);
             s = string[i];
             count=1;
          }
      }
      printf("(%c,%d)",s,count);
      getchar();
      getchar();
}


int main()
{
    char str[1000];
    gets(str);
    int i;
    for(i=0;i<strlen(str);i++)
    {
        if(str[i]<'a')
        str[i]=tolower(str[i]);
    }
    int a=1;
    for(i=0;i<strlen(str);i++)
    {
        if(str[i]!=str[i+1])
        {
        printf("(%c,%d)",str[i]-'a'+'A',a);
        a=1;
        }
        else a++;
    }

}


int main()
{
	char str[1000];
	scanf("%s",str);

	//?????????
{
	int i=0;
	while (str[i]!='\0')
	{
		if (str[i]>='a'&&str[i]<='z')
		{
			str[i]=str[i]-'a'+'A';
		}
		i++;
	}
}
	//samechar??????samecount?????
	char samechar[1000];
	int samecount[1000]={0};
	char tmp;
	tmp=str[0];
	//jishu?samechar?????
	int jishu=0;
	int i1;
	for(i1=0;str[i1]!='\0';i1++)
	{
		if(tmp==str[i1])
		{
			samechar[jishu]=tmp;
			samecount[jishu]++;
		}
		else
		{
			tmp=str[i1];
			jishu++;
			samechar[jishu]=tmp;
			samecount[jishu]++;
		}
	}
	//????
	int i2;
	for(i2=0;i2<=jishu;i2++)
	{
		printf("(%c,%d)",samechar[i2],samecount[i2]);
	}
	return 0;
}


int main()
{
    char str[200];
    cin >> str;
    int len = strlen(str);
    int i,j=0;
    for (i = 0;i < len; i++)
    {
        if (str[i] >='a' && str[i] <= 'z' )
        {
                   str[i] = str[i] - ('a' - 'A');
        }
    }
    char letter[200]={' '};
    int length[200];
    for (i=0;i<=199;i++)
    {
        length[i]=1;
    }
    letter[0] = str[0];
    for (i = 1;i < len; i++)
    {
        if (str[i] == str[i-1] )
        {
            length[j]++;
        }
        else
        {
            j++;
            letter[j]= str[i];
        }
    }
    int kinds = j;

    for(i=0;i<=j;i++)
    {
        cout << "(" << letter[i] << "," << length[i] << ")" ;
    }
    cout << endl;    return 0;
}


main()
{
	int n,length,count=0,i;
	char str[1001],cube;
	scanf("%s",str);
	length=strlen(str);
	for(i=0;i<length;i++)
	{
		if(str[i]>='a'&&str[i]<='z')
		str[i]=str[i]+'A'-'a';
	}
	cube=str[0];
	for(i=0;i<=length;i++)
	{
		if(str[i]==cube)
		count++;
		if(str[i]!=cube)
		{
			printf("(%c,%d)",cube,count);
			cube=str[i];
			count=1;

		}
	}

}


char str[1001],letter[27],temp;
int i,start[27],l,s=1,op='A'-'a',
    opl='a'-'A';
int main()
{

    cin>>str;
    l=strlen(str);
    letter[1]=str[0];
    temp=letter[1];
    start[1]=0;
    for(i=0;i<l;i++)
    {
        if(str[i]==temp||str[i]==temp+op||str[i]==temp+opl)
        continue;
        else
        {
            s++;
            letter[s]=str[i];
            start[s]=i;
            temp=letter[s];
            }
        }
    for(i=1;i<=s;i++)
    {

        if(letter[i]>='a'&&letter[i]<='z')
           letter[i]=letter[i]+op;
        if(i<s)
        {
            cout<<"(";
        cout<<letter[i];
        cout<<",";
        cout<<start[i+1]-start[i];
        cout<<")";
        }
        if(i==s)
        {
            cout<<"(";
        cout<<letter[i];
        cout<<",";
        cout<<l-start[i];
        cout<<")";
        }
        }

    return 0;
}


int main()
{
	int count = 1, flag = 1;
	char a, last = '0';
	while ((a = cin.get()) != '\n')
	{
		flag = 1;
		if (last >= 'a' && last <= 'z')
			if (a == last || a == last - 32)
			{
				count++;
				flag = 0;
			}
		if (last >= 'A' && last <= 'Z')
			if (a == last || a == last + 32)
			{
				count++;
				flag = 0;
			}
		if (flag)
		{
			if (last != '0')
				cout << count << ")";
			switch (a)
			{
			case 'a': cout << "(A,"; break;
			case 'A': cout << "(A,"; break;
			case 'b': cout << "(B,"; break;
			case 'B': cout << "(B,"; break;
			case 'c': cout << "(C,"; break;
			case 'C': cout << "(C,"; break;
			case 'd': cout << "(D,"; break;
			case 'D': cout << "(D,"; break;
			case 'e': cout << "(E,"; break;
			case 'E': cout << "(E,"; break;
			case 'f': cout << "(F,"; break;
			case 'F': cout << "(F,"; break;
			case 'g': cout << "(G,"; break;
			case 'G': cout << "(G,"; break;
			case 'h': cout << "(H,"; break;
			case 'H': cout << "(H,"; break;
			case 'i': cout << "(I,"; break;
			case 'I': cout << "(I,"; break;
			case 'j': cout << "(J,"; break;
			case 'J': cout << "(J,"; break;
			case 'k': cout << "(K,"; break;
			case 'K': cout << "(K,"; break;
			case 'l': cout << "(L,"; break;
			case 'L': cout << "(L,"; break;
			case 'm': cout << "(M,"; break;
			case 'M': cout << "(M,"; break;
			case 'n': cout << "(N,"; break;
			case 'N': cout << "(N,"; break;
			case 'o': cout << "(O,"; break;
			case 'O': cout << "(O,"; break;
			case 'p': cout << "(P,"; break;
			case 'P': cout << "(P,"; break;
			case 'q': cout << "(Q,"; break;
			case 'Q': cout << "(Q,"; break;
			case 'r': cout << "(R,"; break;
			case 'R': cout << "(R,"; break;
			case 's': cout << "(S,"; break;
			case 'S': cout << "(S,"; break;
			case 't': cout << "(T,"; break;
			case 'T': cout << "(T,"; break;
			case 'u': cout << "(U,"; break;
			case 'U': cout << "(U,"; break;
			case 'v': cout << "(V,"; break;
			case 'V': cout << "(V,"; break;
			case 'w': cout << "(W,"; break;
			case 'W': cout << "(W,"; break;
			case 'x': cout << "(X,"; break;
			case 'X': cout << "(X,"; break;
			case 'y': cout << "(Y,"; break;
			case 'Y': cout << "(Y,"; break;
			case 'z': cout << "(Z,"; break;
			case 'Z': cout << "(Z,"; break;
			}
			last = a;
			count = 1;
		}
	}
	cout << count << ")" << endl;
	return 0;
}


int main()
{
    char string[1001];
    gets(string);
    int n;
    n=strlen(string);
    int i;
    int m=1;
    for(i=0;i<n;i++)
    {
                    if(string[i]>=97)
                    string[i]=string[i]-32;
    }
    for(i=0;i<n;i++)
    {
                    if(string[i]==string[i+1])
                    {
                        m++;
                    }
                    else
                    {

                         printf("(%c,%d)", string[i], m);
                         m=1;
                    }
    }

    return 0;
}


int main(){
	int n=1,i,j,m=0;
	char k[1001],y[27]="abcdefghijklmnopqrstuvwxyz",z[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int s[26];
	scanf("%s",k);
    for(i=0;i<strlen(k);i++){
    for(j=0;j<26;j++){
    if(k[i]==y[j])
    k[i]=z[j];}}
	for(i=0;i<strlen(k);i=i+n){
    printf("(%c,",k[i]);
    for(n=0;n<(strlen(k)-i);n++){
    if(k[i+n]==k[i])
    m++;
    else
    break;}
    printf("%d)",m);
    m=0;}
}


int main()
{
	char str[1001];
	int len,count=0;
	int i;
	char c;
	cin>>str;
	len=strlen(str);
	for(i=0;i<len;i++)
	{
		if(str[i]>='a'&&str[i]<='z')
			str[i]-=32;
	}
	c=str[0];
	for(i=0;i<len;i++)
	{
		if(str[i]==c)
		{
			count++;
		}
		else
		{
			cout<<"("<<str[i-1]<<","<<count<<")";
			c=str[i];
			count=1;
		}
	}
	i--;
	cout<<"("<<str[i]<<","<<count<<")";
	cout<<endl;

	return 0;
}


main()
{
      char s[10000];
      int i;
      gets(s);
      int l=strlen(s);
        for(i=0;i<l;i++)
        for(int j='a';j<='z';j++)
        if(s[i]==j) s[i]=j-32;
        char max=s[0];int k=0;
      for(i=0;i<=l;i++)
      {
      if(s[i]==max) k++;
      else
       {
           printf("(%c,%d)",max,k);
           max=s[i];
           k=0;
           i--;
           }

}
      getchar();getchar();
      }


// 2011???.cpp : ??????????????
//
int main()
{
	char str[10000];
	char now;
	int len;
	cin>>str;
	len=strlen(str);
	int num=1;
	int time=0;
	for(int j=0;j<len;j++)
	{
		if(str[j]<'z'+1&&str[j]>'a'-1) str[j]=str[j]+'A'-'a';
	}
	now=str[0];
	cout<<'('<<now<<',';
	for(int i=1;i<len;i++)
	{
		if(str[i]==str[i-1]) num=num+1;
		else
		{
			cout<<num<<')';
			now=str[i];
			num=1;
			cout<<'('<<now<<',';
		}
	}
	cout<<num<<')'<<endl;
	return 0;
}


int main()
{
	char str[1000], t;
	int i, count = 0;
	cin.getline(str,1000);
	int len = strlen(str);
	for (i = 0; i < len; i++)
	{
		if (str[i] >= 97)
			str[i] -= 32;
	}
	t = str[0];
	i = 0;
	while (i < len)
	{
		if (t == str[i])
			count++;
		else
		{
			cout << "(" << t << "," << count << ")";
			count = 1;
			t = str[i];
		}
		i++;
	}
	cout << "(" << t << "," << count << ")" << endl;
	return 0;
}


int main()
{
    char letter[1000];
    int nletter[1000];
    char str[1000];

    memset(letter,'\0',1000);
    memset(str,'\0',1000);

    for(int i=0;i<=1000-1;i++)nletter[i]=1;

    cin>>str;
    int len=strlen(str);
    int n=0;

    letter[0]=str[0];

    for(int i=0;i<=len-1;i++)
    {
        if(letter[n]!=str[i+1]&&(letter[n]!=str[i+1]+'A'-'a')&&(letter[n]!=str[i+1]-'A'+'a'))
        {
            letter[++n]=str[i+1];
        }
        else
        {
            nletter[n]++;
        }
    }
    for(int i=0;i<=n-1;i++)
    {
        if(letter[i]>'Z')letter[i]+=('A'-'a');
    }

    for(int i=0;i<=n-1;i++)
    {
        cout<<"("<<letter[i]<<","<<nletter[i]<<")";
    }
    cout<<endl;
    return 0;
}


typedef struct
{
	char c;
	int count;
} letterCount; //????????????????

int main()
{
	int i,j;
	char str[MAXLENGTH];
	letterCount lc[MAXLENGTH]; //?????
	//??
	fgets(str, MAXLENGTH, stdin);

	//???????????
	for (i = 0; i < MAXLENGTH; i++)
	{
		if(str[i] == '\n')
			break;
		if (str[i] >=97 && str[i] <= 122)
			str[i] = str[i] - 32;
	}

	//???????
	j = 0; //????????
	i = 0; //?????

	lc[j].c = str[0];
	lc[j].count = 1;
	while (true)
	{
		if (str[i] == str[i + 1])
		{
			lc[j].count++;
			i++;
		}
		else
		{
			if (str[i + 1] == '\n')
				break;

			j++;
			lc[j].c = str[i + 1];
			lc[j].count = 1;
			i++;
		}
	}

	//??
	for (int i = 0; i <=j; i++)
	{
		printf("(%c,%d)", lc[i].c, lc[i].count);
	}
	printf("\n");
	return 0;
}


int main()
{
	int i,len,sum;
	char temp,str[1000]={0};
	gets(str);
	len=strlen(str);
	for(i=0;i<len;i++)
		if(str[i]>=97)
			str[i]=str[i]-32;
	temp=str[0];
	sum=0;
	for(i=1;i<len;i++){
		if(str[i]!=temp){
			printf("(%c,%d)",str[i-1],sum+1);
			sum=0;
			temp=str[i];
		}
		else
			sum++;
	}
	printf("(%c,%d)",temp,sum+1);
	return 0;
}


char l(char c)
{
if (c>='a'&&c<='z')
     return c+'A'-'a';
else
     return c;
}

int main()
{
    char s[1001];cin>>s;
    char c=l(s[0]);
    int t=1;
    for (int i=1;i<=strlen(s);i++)
    {if (c==l(s[i]))
    t++;
    else
    {
    cout<<'('<<c<<','<<t<<')';
            c=l(s[i]);
    t=1;
        }
    }
    cout<<endl;
    return 0;
}


int main()
{
    char string[1000];
    gets(string);
    int l,i,j,count;
    l=strlen(string);
    for(i=0;i<l;i++)
    {
           if(string[i]<'A'||string[i]>'Z')
           string[i]=string[i]-'a'+'A';
    }
    for(i=0;i<l;i++)
    {
                    count=0;
                    for(j=i;j<l;j++)
                    {
                                    if(string[i]==string[j])
                                    count++;
                                    else
                                    break;
                    }
                    if(count!=0)
                    {
                    printf("(%c,%d)",string[i],count);
                    i=i+count-1;
                    }
    }
    getchar();
    getchar();
}


char big(char x);
int main()
{
	char a[1003];
	char t;
	int sum=0,i,len;
	cin>>a;
	len=strlen(a);
	sum=1;
	t=big(a[0]);
	for(i=1;i<len;i++)
	{
		if(big(a[i])==t) sum++;
		if(big(a[i])!=t)
		{
			cout<<"("<<t<<","<<sum<<")";
			sum=1;
			t=big(a[i]);
		}
	}
	cout<<"("<<t<<","<<sum<<")";
	return 0;
}
char big(char x)
{
	if(x>='a'&&x<='z') return(x-'a'+'A');
	else return x;
}


int main()
{
     char str[1001];
     int len , i,temp ,sum = 1 ,k = 1;
     scanf("%s",str);
     len = strlen( str );
      temp = 0;
     for( i = 0 ;i <= len+1 ;i ++  )
     {
         while( str[k] == str[temp] || str[k] == str[temp]+32 || str[k] == str[temp ] - 32 )
           {
             sum ++;
             k++;
           }

           if( str[temp] >= 'a' && str[temp] <= 'z')
           str[temp]-= 32;
           printf( "(%c,%d)",str[temp],sum );
           sum = 1;
           temp = k  ;
           i = k+1;
           k = k+1;
     }
}


int f(char c)
{   if ((c>'Z')&&(c<='z'))
    c=c-'a'+'A';
    return c;
}
main()
{ int j=1;
  char str[1050];
  scanf("%s",str);
  for (int i=0;i<=strlen(str)-1;i++)
  {str[i]=f(str[i]);
  }
  for(int i=0;i<=strlen(str)-1;i++)
  {if(str[i]==str[i+1])
   {j=j+1;
   }
   else
   {printf("(%c,%d)",str[i],j);
    j=1;
   }
  }
}


main()
{
    char string[1001];
    int time,m,n,i,j,k;
    gets(string);
    m=strlen(string);
    for (i=0;i<m;i++)
    {
    	if (string[i]>='a'&&string[i]<='z')
    	    string[i]=string[i]-32;
    }
    time=1;
    for (i=0;i<m;i++)
    {
		if (string[i+1]==string[i])
		{
			time=time+1;
		}
		else
		{
			printf ("(%c,%d)",string[i],time);
			time=1;
		}
    }
}


int main()
{

	char string[1000];
	gets(string);

	int len=0;
	int count=0;
	while(string[len])
		len++;

	int index=0;

	char first_letter=toupper(string[0]);

	for(index=0;index<=len;)
    {
		if(toupper(string[index])==first_letter)
		{
			count++;
			index++;
		}
		else
		{

				printf("(%c,%d)",first_letter,count);
			    count=0;
			    first_letter=toupper(string[index]);

		}
	}

	return 0;
}


void change(char words[])
{
	int len = strlen(words);
	int i = 0;
	int d = 'A' - 'a';
	for(i = 0; i < len; i++)
	{
		if(words[i] <= 'z'&& words[i] >= 'a')
		{
			words[i] = words[i] + d;
		}
	}
}
int main()
{
	char words[100];
	cin >> words;
	change(words);
	char mark = words[0];
	int sum = 0, len = strlen(words);
	for(int i = 0; i < len; i++)
	{
		if(words[i] == mark)
		{
			sum++;
		}
		else
		{
			cout << "(" << mark << "," << sum << ")";
			mark = words[i];
			sum = 1;
		}
	}
	cout << "(" << mark << "," << sum << ")";
	return 0;
}


int main()
{
	char a[1001];
	int i, temp;
	cin.getline(a, 1001);
	int len = strlen(a);
	temp = 0;
	while (temp < len)
	{
		i = temp + 1;
		while ((i < len) && (a[i] == a[temp] || a[i] - 'a' == a[temp] - 'A' || a[i] - 'A' == a[temp] - 'a'))
			i ++;
		if (a[temp] <= 'Z')
			cout << "(" << (char) a[temp] << "," << i - temp << ")";
		else
			cout << "(" << (char) (a[temp] - 'a' + 'A') << "," << i - temp << ")";
		temp = i;
	}
	return 0;
}


int finder(int a,int b)
{
	int c;
	for(;a;a=a/2)
		for(c=b;c>=a;c=c/2)
			if(a==c)
			{
				printf("%d",c);
				return 0;
			}
}

int main()
{
	int a,b,c,d;
	scanf("%d%d",&a,&b);
	finder(a,b);
	return 0;
}


int y[1000]={0};
int *p,*q;
int z[1000]={0};

int* count1(int n)
{int i,j,k,m,l;
	i=0;
	while(n!=0)
	{   y[i]=n;
		n=n/2;

		i++;
	}
	return y;
}
int* count2(int x)
{int i,j,k,m,l;
	i=0;
	while(x!=0)
	{   z[i]=x;
		x=x/2;

		i++;
	}
	return z;
}
int compare()
{
	int i,j;
	for(i=0;i<1000;i++)
	{
		for(j=0;j<1000;j++)
		{
			if(*(p+i)==*(q+j)) goto MM;
		}
	}
MM:
	return *(p+i);
}
void main()
{
	int i,j,s,t,c;

	scanf("%d%d",&s,&t);
	p=count1(s);
	q=count2(t);
	c=compare();
	printf("%d\n",c);
scanf("%d",&c);
}


int main()
{
	int m,n;
	scanf("%d%d",&m,&n);
	while(m!=n)
	{
		if(m>n)
			m=m/2;
		else n=n/2;
	}
	printf("%d",m);
	return 0;
}


/*
 * assignment.cpp
 *
 *  Created on: 2010-11-23
 *      Author: ??
 *      ???????
 */

int main(){
	int x,y;
	int i=0,j=0;
	cin>>x>>y;
	while(1){
		if(pow(2,i)>x)
			break;
		i++;
	}
	while(1){
		if(pow(2,j)>y)
			break;
		j++;
	}
	while(i>j){
		x=x/2;
		i--;
	}
	while(i<j){
		y=y/2;
		j--;
	}
	while(1){
		if(x==y)break;
		else{
			x=x/2;
			y=y/2;
		}
	}
	cout<<x;
	return 0;
}


int main()
{
    int a,b;
    cin>>a>>b;
    while(1)
    {
        while(a>b)
        {
            a=a/2;
        }
        while(b>a)
        {
            b=b/2;
        }
        if(a==b)  break;
    }
    cout<<a<<endl;
}


//ÊµÖÊÉÏÊÇÁ½¸ö¶þ½øÖÆÊý£¬×î¶àÇ°¶àÉÙÎ»ÏàÍ¬£¬ÔòÇ°¶àÉÙÎ»¶ÔÓ¦µÄ¶þ½øÖÆÊý¼´ÎªËùÇó
//Ç·È±ÓÅ»¯

int main()
{
	int x, y, memo;
	cin >> x >> y;
	memo = y;
	do {
		do {
			if (x == y) {
				cout << x;
				return 0;
			}
			y = y >> 1;
		} while (y);
		x = x >> 1;
		y = memo;
	} while (x);
}


int two(int n)   //?2?n??
{
	int i,sum=1;
	for(i=1;i<=n;i++)
	{
		sum=sum*2;
	}
	return sum;
}

int pand(int x)  //??x????
{
	int i,sign=0,m;
	for(i=1;sign==0;i++)
	{
		if(x>=two(i)&&x<two(i+1))
		{m=i+1;
		 sign=1;}
	}
	return m;
}

int main()
{
	int result,i,sign=0;
	int x,y,lx,ly;
	int xx[20],yy[20];
	scanf("%d%d",&x,&y);
	if(x==1||y==1)
	result=1;
	else if(x==y)
		result=x;
	else
	{
		lx=pand(x);
		ly=pand(y);
		xx[lx-1]=x;
		yy[ly-1]=y;
		for(i=2;i<=lx;i++)
		{
			xx[lx-i]=x/2;
			x=x/2;
		}
		for(i=2;i<=ly;i++)
		{
			yy[ly-i]=y/2;
			y=y/2;
		}

		for(i=0;sign==0;i++)
		{
			if(xx[i]!=yy[i])
			{sign=1;
			 result=xx[i-1];}
		}

	}

	printf("%d",result);

	return 0;
}


int turn(int a,int b)
{
	int i,k;
	if(a==b)
		k=a;
	if(a>b)
	{
		k=turn(a/2,b);
	}
	if(a<b)
	{
		k=turn(a,b/2);
	}
	return k;
}
void main()
{
	int a,b;
		scanf("%d%d",&a,&b);
		printf("%d",turn(a,b));
}


void main()
{
	int a(int x,int y);
	int x,y,z;
	scanf("%d %d",&x,&y);
	z=a(x,y);
	printf("%d\n",z);
}

int a(int x,int y)
{
	int m;
	if(x==y) m=x;
	else if(x<y) m=a(x,y/2);
	else m=a(x/2,y);
	return(m);
}


void main()
{
	int found(int x,int y);

	int x,y,z;

	scanf("%d %d",&x,&y);

	z=found(x,y);

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

int found(int x,int y)
{
	int i,j,a[10],b[10];
	for(i=0;i<10;i++)
	{
		a[i]=x;
		x=x/2;
	}

	for(i=0;i<10;i++)
	{
		b[i]=y;
		y=y/2;
	}

	for(i=0;i<10;i++)
		for(j=0;j<10;j++)
			if(a[i]==b[j])
			{
				return a[i];
				break;
			}
}


int main()
{
	int x,y;    //????x?y???????
	cin>>x>>y;    //??x?y
	void commoninteger(int x,int y);   //????commoninteger
	commoninteger(x,y);    //????commoninteger?????
	return 0;
}

void commoninteger(int x,int y)   //????commoninterger??????x?y???????????
{
	if(x==y)      //??x=y?????????x????
		cout<<x;
	else {
		if(x>y)      //??x>y???x??2???????commoninteger??????y??2???????commoninteger??
			commoninteger(x/2,y);
			else commoninteger(x,y/2);
	}
}


int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	int xi,yj;
	int i,j;
	for(i=0;i<15;i++)
	{
		xi=x/(pow(2,i));
		for(j=0;j<15;j++)
		{
			yj=y/(pow(2,j));
			if(yj==xi)
			{	printf("%d\n",yj);
			break;
			}
		}
		if(yj==xi)
			break;
	}
	return 0;

}


/*
 * Homework7.6BinaryTree.cpp
 *
 *  Created on: 2013-11-22
 *      Author: JuiceHe
 */
int main()
{
	int x,y;
	cin>>x>>y;
	int find(int,int);
	cout<<find(x,y)<<endl;
}
int find(int x,int y)
{
	if(x==y)return x;//??????????????
	if(x>y)return (find(x/2,y));//??????????????????????
	else return (find(x,y/2));
}


int jd(int m,int x)
{
	if(m==0)return x;
    if(x==1)return 1;
	else return jd(m-1,x/2);
}
int main()
{
	int a,b;
	cin>>a>>b;
	int n=0;
	for(int i=0;i<=a;i++){
		if(n==1)break;
		for(int k=0;k<b;k++){
			if(jd(i,a)==jd(k,b)){cout<<jd(i,a)<<endl;
			    n=1;
			    break;}

		}}
return 0;
}


int s(int x,int y);
int main(int argc)
{  int x,y;
    cin>>x>>y;
	cout<<s(x,y);          //??????
	return 0;

}
int s(int x,int y)
{
 if(x==y)
 {return x;}        //?????????????
 else if(x>y)
 {return s(x/2,y);}              //?????????????2????
 else
 {return s(x,y/2);}
};


int a1(int n)
{
	if (n/2==0)
	return 1;
	else
	return (1+a1(n/2));
}
void search(int a,int b)
{
	if (a1(a)==a1(b))
	{
		if (a/2==b/2&&a/2!=b/2)
		{
			cout<<a/2;
		}
		else if(a==b)
		{
			cout<<a;
		}
		else search(a/2,b/2);
	}
		if (a1(a)>a1(b))
		{
			search(a/2,b);
		}
		if (a1(a)<a1(b))
		{
			search(a,b/2);
		}
}

int main()
{
	int x,y;
	cin>>x>>y;
	search(x,y);

}


int main()
{
    int xunzhao(int x,int y);
	int x,y,q;
	scanf("%d %d",&x,&y);
	q=xunzhao(x,y);
	printf("%d",q);

}
int xunzhao(int x,int y)
{
	int q;
	if(x==y)
	q=x;
	if(x>y)
	return  xunzhao(x/2,y);
	if(x<y)
	return  xunzhao(x,y/2);
	return q;
}


int same(int a,int b)
{
	if (a == 1||b == 1)
		return 1;
	else if (a == b)
		return a;
	else if (a>b)
    {
    	if (a%2 == 0) return same (a/2,b);
    	else return same((a-1)/2,b);
    }
    else if (b>a)
    {
    	if (b%2 == 0) return same (a,b/2);
    	else return same(a,(b-1)/2);
    }
	return 0;
}

int main(void)
{
	int x,y;
	cin>>x>>y;
	cout<<same(x,y)<<endl;
	return 0;
}


void gaoxiao(int m,int n)
{
	if(m>n)
		m=m/2;
	if(m<n)
		n=n/2;
	if(m==n)
		cout<<m<<endl;
	else
		gaoxiao(m,n);
}
int main()
{
	int m,n;
	cin>>m>>n;
	gaoxiao(m,n);
	char mm;
	cin>>mm;
	return 0;
}


int c(int , int);
int main(void){
	int a,b;
	cin>>a>>b;
	cout<<c(a,b)<<endl;
	return 0;
}
int c(int x, int y){
	if(x%y==0) return y;
	if(x>y) return c(x/2,y);
	if(x<y) return c(x,y/2);
}


int F(int a)
{
	if(a%2==0)
		a=a/2;
	else
		a=(a-1)/2;
	return a;
}

int main()
{
	int a,b;
	cin>>a>>b;
	while(a!=b)
	{
		if(a>b)
			a=F(a);
		if(a<b)
			b=F(b);
	}
	cout<<a;
	return 0;
}


int a(int,int);
main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	printf("%d",a(max(x,y),min(x,y)));
}
int a(int m,int n)
{
	while(m>n)
	{
		m/=2;
	}
	if(m==n)
		return m;
	else
		return a(n,m);
}


int main()
{
	int back(int x,int y);
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n",back(x,y));

	return 0;
}

int back(int x,int y)
{
	int a[100],b[100];
	int i=0,j;
	int n1,n2;
	while (x>0)
	{
		a[i]=x;
		x=x/2;
		i++;
	}
	n1=i;
	i=0;
	while (y>0)
	{
		b[i]=y;
		y=y/2;
		i++;
	}
	n2=i;
	for (i=0;i<n1;i++)
	{
		for (j=0;j<n2;j++)
		{
			if (a[i]==b[j])
			{
				return a[i];
				break;
			}
		}
	}
}


int point(int num)
{
	if(num==1)
	{
		return 1;
	}
	else
	{
		if(num%2==0)
		{
			return num/2;
		}
		else
		{
			return (num-1)/2;
		}
	}
}
int main()
{
	int point(int num);
	int x,y;
	scanf("%d %d",&x,&y);
	int X[11]={x},Y[11]={y},i,j;
	for(i=1;i<11;i++)
	{
		X[i]=point(X[i-1]);
		Y[i]=point(Y[i-1]);
	}
	for(i=0;i<11;i++)
	{
		int signal=0;
		for(j=0;j<11;j++)
		{
			if(X[i]==Y[j])
			{
				printf("%d\n",X[i]);
				signal=1;
				break;
			}
		}
		if(signal==1)
		{
			break;
		}
	}
	return 0;
}


/*
 * 006.cpp
 *
 *  Created on: 2012-11-24
 *      Author: asus
 */
int common(int x, int y)//??common??
{
	if(x > y) return common(x / 2, y);//???????????2
	if(x < y) return common(x, y / 2);
	return x;//?????
}

int main()//???
{
	int m = 0, n = 0;
	cin >> m >> n;
	cout << common(m, n) << endl;//????
	return 0;
}


int tree (int,int);               // ??????
int power (int,int);              // ??????
int main ()
{
 int x,y;
 cin >> x >> y;
 cout << tree (x,y) << endl;
 return 0;
}
int tree (int a, int b)
{
 int i,c;
 for (i=0;i<11;i++)
 {
  c=a/power(2,i);
  if (b==c)
   return b;
 }
 for (i=0;i<11;i++)
 {
  c=b/power(2,i);
  if (a==c)
   return a;
 }
 if (a==1||b==1)
  return 1;
 return tree (a/2,b/2);
}
int power (int m,int n)
{
 int j,sum=1;
 for (j=0;j<n;j++)
  sum=sum*m;
 return sum;
}


int main()
{
	void Hanshu(int a,int b);
	int a,b,k;
	scanf("%d %d",&a,&b);
	Hanshu(a,b);
	return 0;
}

void Hanshu(int a,int b)
{
	if(a==b) printf("%d",a);
	else if(a>b)
	{
		a=a/2;Hanshu(a,b);
	}
	else
	{
		b=b/2;Hanshu(a,b);
	}
}


int f(int ,int);
int main()
{
    int x,y,i,j,k=0;
    cin>>x>>y;
    for(i=1;i<=500;i++)
      { for(j=1;j<=500;j++)
       {   if(f(x,i)==f(y,j)) {cout<<f(y,j)<<endl;k=1;break;}
           else continue;}
           if(k==1) break;}
           return 0;
           }
int f(int a,int b)
{
    int m;
    if(b==1) m=a;
   else if(b==2) m=a/2;
    else m=f(a,b-1)/2;
    return m;
}


//============================================================================
// Name        : 7.6.cpp
// Author      : Zhang Yu
// Version     :
// Copyright   : Your copyright notice
// Description : ???
//============================================================================

int findknot(float,float);
int findknot(float x,float y)
{
	if (x==y)//??x,y???????
		return (int)x;//x????
	if (ceil(log((double)x)/log(2))==ceil(log((double)y)/log(2)))//??x,y????
		return findknot(floor(x/2),floor(y/2));//?????
	else//??x,y?????
	{
		float tempmax=max(x,y);
		float tempmin=min(x,y);
		x=tempmax;
		y=tempmin;
		//??????x???????
		return findknot(floor(x/2),y);//x??????y??
	}
}
int main() {
	int inputx,inputy;
	cin >>inputx>>inputy;
	cout <<findknot((float)inputx,(float)inputy);
	return 0;
}


int last(int k)
{
	if (k%2==0)
	{
		return (k/2);
	}
	else
	{
		return ((k-1)/2);
	}
}

int main()
{
	int x,y;
	cin>>x>>y;
	while (x!=y)
	{
		if (x>y)
		{
			x = last(x);
		}
		else
		{
			y = last(y);

		}
	}
	cout<<x;
}


/*
 * 1062.cpp
 *
 *  Created on: 2011-11-15
 *      Author: sony
 */

int route(int x,int y){                //??????,????????????,???????????????
	if(x==y) return x;
	if(x>y) return route(x/2,y);
	if(x<y) return route(x,y/2);
	else return route(x/2,y/2);
}

int main()
{
	int x,y;
	cin>>x>>y;
	cout<<route(x,y)<<endl;
	return 0;
}


int main()
{
	int f(int x,int y);
	int x,y,i,j,k,l;
	scanf("%d%d",&x,&y);
	l=f(x,y);
	printf("%d",l);
	scanf("%d",&j);
	return 0;
}
int f(int x,int y)
{
	int a;
	if(x==1||y==1) a=1;
	else if(x%2==0&&y%2==1&&x+1==y) a=x/2;
	else if(x==y) a=x;
	else if(x>y) a=f(x/2,y);
	else a=f(x,y/2);
	return a;
}


int shangyigejiedian(int);

int main()
{
	int m,n,a,b;
	cin>>a>>b;
	m=a;
	n=b;

	do
	{a=m;
	do
	{
		if (a==b)
		{
			cout<<a<<endl;
			return 0;
		}
		else a=shangyigejiedian(a);

	}while(a>=1);

	b=shangyigejiedian(b);
	}while(b>=1);

	return 0;
}

int shangyigejiedian(int i)
{
	int shangyigejiedian;
	if(i==1) return 0;
	else
	{
		if(i%2==0) return i/2;
		else return(i-1)/2;
	}
}


int main()
{
	int searchjoint(int x,int y);
	int x,y,flag;
	scanf("%d%d",&x,&y);
	if(x==y)
		flag=x;
	else if(x>y)
		flag=searchjoint(y,x);
	else
		flag=searchjoint(x,y);
	printf("%d",flag);
	return 0;
}
int searchjoint(int x,int y)
{
	int i,j,t,flag=1;
	for(i=0;i<10 && x>=1;i++)
	{
		for(j=0,t=y;j<10 && t>=1;j++)
		{
			t=t/2;
			if(x==t)
			{
				flag=x;
				break;
			}
		}
		if(flag!=1)
			break;
		x=x/2;
	}
	return flag;
}


int main()
{
    int xpath[100]={0},ypath[100]={0};
    int xi=0,yi=0;
    cin>>xpath[0]>>ypath[0];
    while(xpath[xi]!=1)
	{
	      xpath[xi+1]=xpath[xi]/2;
	      xi++;
	}
    while(ypath[yi]!=1)
	{
	      ypath[yi+1]=ypath[yi]/2;
	      yi++;
}
while(xi>=0 && yi>=0)
{
	if(xpath[xi]!=ypath[yi])
	{
		cout<<xpath[xi+1]<<endl;
		return 0;
	}
	xi--;
	yi--;
}
cout<<(xi<0?xpath[0]:ypath[0])<<endl;
return 0;
}


int erchashu(int a,int b)
{
	if(a==b) return(a);
	if(a>b) return(erchashu(a/2,b));
	if(a<b) return(erchashu(a,b/2));
}
void main()
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	c=erchashu(a,b);
	printf("%d",c);
}


void tree(int a,int b)
{
	if(a==b) printf("%d",a);
	else
	if(a>b)
	{
		if(a>=2*b)
			tree(a/2,b);
		else
			tree(a/2,b/2);
	}
	else
		tree(b,a);
}

int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	tree(x,y);
	return 0;
}


int common(int a,int b);
void main()
{
    int x,y;
	scanf("%d %d",&x,&y);
	printf("%d",common(x,y));
}
int common(int a,int b)
{
	if(a==b) return a;
	if(a>b) return common(a/2,b);
	return common(a,b/2);
}


int main(int argc, char* argv[])
{
	int iaX[11], iaY[11];
	int x,y, i, j, ilenx=0, ileny=0;
	int itemp;
	int imin;
	scanf("%d%d", &x, &y);
	for (i=0; i<11; i++)
	{
		iaX[i]=-1;
		iaY[i]=-1;
	}

	i=0;
	while(x>0)
	{
		iaX[i++]=x;
		x/=2;
		ilenx++;
	}
	i=0; j=ilenx-1;
	while(i<j)
	{
		itemp=iaX[i];
		iaX[i]=iaX[j];
		iaX[j]=itemp;
		i++; j--;
	}

	i=0;
	while(y>0)
	{
		iaY[i++]=y;
		y/=2;
		ileny++;
	}
	i=0; j=ileny-1;
	while(i<j)
	{
		itemp=iaY[i];
		iaY[i]=iaY[j];
		iaY[j]=itemp;
		i++; j--;
	}

	imin=ilenx>ileny? ileny:ilenx;
	for (i=0;i<imin; i++)
	{
		if (iaX[i]!=iaY[i])
		{
			break;
		}
	}
	printf("%d", iaX[--i]);

	return 0;
}


int main(int a,int b){scanf("%d%d",&a,&b);while(a!=b){while(a>b)a/=2;while(a<b)b/=2;}printf("%d\n",a);}


void count (int ,int );
int flag;
int main()
{  int m,n,temp;
  cin>>m>>n;
  if( m > n )
  {
	  temp = n;
	  n = m;
	  m = temp;
  }
  flag = 0;
  for(int i=m;i>=1 && flag  == 0;i = i/2 )
  {
	count (n,i);
  }
  return 0;
}
 void count (int n,int i)
 {
	 if( n < 1 || n < i )
	 {
		 return ;
	 }
	 else
	 {
		 if(i == n)
		 {
	    	cout<<i<<endl;
			flag = 1;
			return ;
		 }
		 else
		 {
			count(n/2,i);
		 }
	 }
	 return ;
 }


/*
 * erchashudigui.cpp
 *
 *  Created on: 2010-11-26
 *      Author: 378073652
 */

int s=0;

int common(int x ,int y,int s){
	if(x==y) return x;
	if(x>y)  {s++;   return common(x/2,y,s);}
	if(x<y)   {      s++;   return common(x,y/2,s);}
}
int main(){
	int a,b;

	cin>>a>>b;
	cout<<common(a,b,s)<<endl;

 }


int main()
{
	int common(int,int);
	int x=0,y=0;
	cin>>x>>y;
	cout<<common(x,y)<<endl;
	return 0;
}
int common(int x,int y)
{
	if(x==y)
		return x;
	if(x>y)
		return common(x/2,y);
	else
		return common(x,y/2);
}


int x(int a,int b);
main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",x(a,b));
}
int x(int a,int b)
{
	if(a>b)
	{a=a/2;
	return x(a,b);}
    if(a<b)
	{b=b/2;
	return x(a,b);}
	if(a=b)
	return a;
}


int count(int b,int c)
{
	if (c==1) return 1;
	long k,i,sum=0;
	double t=c;
	for (i=b;i<=c;i++)
       if (c%i==0)
		   sum+=(count(i,c/i));
    return sum;
}

void main()
{
	int n,m,p[2000]={0},sum=0,tmp;
	scanf("%d%d",&n,&m);
	if (n>m)
	{
		tmp=n;
		n=m;
		m=tmp;
	}
	do
	{
		p[n]=1;
		n=n/2;
	} while (n>0);
	do
	{
		if (p[m])
		{
			printf("%d",m);
			return;
		}
		m=m/2;
	} while (m>0);
}


int x,y;
int *p1=&x;
int *p2=&y;
void Read()
{
	scanf("%d%d",p1,p2);
}
/*int array for Pathway a[11],b[11]*/
int a[11]={0},b[11]={0};
/*int Function return Answer (x>=2^(Answer-1)&&x<(2^Answer))   as  FuncofA  */
int FuncofA(int X)
{
	int i;
	for(i=1;;i++)
	{
		if((pow(2.0,i-1)<=X)&&pow(2.0,i)>X)
		{
			return i;
		}
		else
		{}
	}
}
/*Function for binary tree  as  FuncofB*/
void FuncofB()
{
	int i;
	for(i=(FuncofA(x));i>=1;i--)
	{
		a[i-1]=x;
		x/=2;
	}
	for(i=(FuncofA(y));i>=1;i--)
	{
		b[i-1]=y;
		y/=2;
	}
}
void main()
{
	Read();
	if(x==y)
	{
		goto equal;
	}
	else
	{
		goto unequal;
	}
equal:
	printf("%d",x);
	goto End;
unequal:
	FuncofB();
	int i;
	for(i=1;;i++)
	{
		if(a[i-1]==b[i-1])
		{}
		else
		{
			printf("%d",a[i-2]);
			break;
		}
	}
End:
	;
}


int kuai(int x,int y);
int main()
{
    int a,b;
    cin>>a>>b;
    kuai(a,b);
    return 0;
}

int kuai(int x,int y)
{
    if(x==y)
    cout<<x<<endl;
    if(x<y)
    kuai(x,y/2);
    if(x>y)
    kuai(x/2,y);
    return x;
}


 void line(int a,int x[],int num)
{
	x[num]=a;
	num++;
	if(a==1)
	{
		return;
	}
	else{
	if(a%2==0)
	{
		line(a/2,x,num);
	}
	else{
		line((a-1)/2,x,num);

	}
	}
}

int main()
{

	int x[101],y[101];
	int i,j,k,flag=0;
	int a,b;
	memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
	cin>>a>>b;
	line(a,x,1);
	line(b,y,1);
	for(i=1;x[i]!=0;i++)
	{
		for(j=1;y[j]!=0;j++)
		{
			if(x[i]==y[j])
			{
				cout<<x[i]<<endl;
				flag=1;
				break;
			}
			if(flag==1)
			{
				break;
			}
		}
	}

	return 0;

}


//
//  main.cpp
//  Homework
//
//  Created by ??? on 13-11-17.
//  Copyright (c) 2013? ???. All rights reserved.
//

int main()
{
    int x,y,sx,sy,nx[11],ny[11];
    cin>>x>>y;
    nx[10]=x;
    ny[10]=y;

    for(int i=10;i>0;i--)
        nx[i-1]=nx[i]/2;
    for(int i=10;i>0;i--)
        ny[i-1]=ny[i]/2;

    for(sx=0;sx<11;sx++)
        if(nx[sx]!=0)
        {
            sx--;
            break;
        }
    for(sy=0;sy<11;sy++)
        if(ny[sy]!=0)
        {
            sy--;
            break;
        }

    for(int i=0;i<11;i++)
    {
        if(nx[sx]!=ny[sy])
            break;
        sx++;
        sy++;
    }

    cout<<nx[sx-1]<<endl;

    return 0;
}


/*
*???.cpp
*??
*2011?11?16?
*?????xi?
*/
int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
int min(int c,int d)
{
	if(c<d)
		return c;
	else
		return d;
}
int main()
{
	int inter,x,y,t1,t2;
	cin>>x>>y;
	t1=x;
	t2=y;
	if(t1==t2)
		cout<<t1<<endl;
	else
		{
			while(1)
			{
				inter=t1;
				t1=max(t1,t2);
				t2=min(inter,t2);
				t1=t1/2;
				if(t1==t2)
					{cout<<t1<<endl;break;}
			}
		}
	return 0;
}


int div(int a)
{
	if(a%2==1)a=(a-1)/2;
	else a=a/2;
	return a;
}
int compare(int a, int b)
{
	if(a>b){
		a=div(a);
		compare(a,b);}
	else if (a<b){
		b=div(b);
		compare(a,b);}
	else return(a);
}
void main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	a=compare(a,b);
	printf("%d",a);
}


int N[MAX];

int x_iter(int x){
  if(N[x-1]==1) return x;
  else{
    N[x-1]=1;
    x_iter(x/2);
  }
}

int main(){
  int x,y;
  cin>>x>>y;
  memset(N,0,sizeof(N));
  x_iter(x);
  cout<<x_iter(y);
  return 0;
}


int common(int x,int y);
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	int result=common(x,y);
	printf("%d\n",result);
	return 0;
}
int common(int x,int y)
{
	if(x==y)
	{
		return x;
	}
	else if(x>y)
	{
		return common(x/2,y);
	}
	else
	{
		return common(x,y/2);
	}
}


int x,y;
int maxn;
int dfs(int n){
	int r=0;
	if(n==x||n==y)r++;
	if(n>maxn)return 0;
	r+=dfs(2*n)+dfs(2*n+1);
	if(r==2){
		cout<<n;
		exit(0);
	}
	return r;
}
int main(){
	cin>>x>>y;
	maxn=x>y?x:y;
	dfs(1);
	cout<<x;
}


int search(int x1,int x2)
{
	int i;
	for(i=0;i<=10;i++)
	{
	   if(x1>=pow(2,i)&&x1<pow(2,i+1)&&x2>=pow(2,i)&&x2<pow(2,i+1))
		   return x1;
	   else continue;
	   }
	  x1=x1/2; return search(x1,x2);

}
int equal(int x1,int x2)
{
   if(x1==x2)return x1;
   else
   {x1=x1/2;x2=x2/2;return equal(x1,x2);}

}

int main()
{
  int x1,x2,temp;
  cin>>x1>>x2;
  if(x1<x2)
	{
      temp=x1;
	  x1=x2;
	  x2=temp;

	}
  x1=search(x1,x2);
  cout<<equal(x1,x2);
  return 0;

}


int log(int n)
{
    int i=-1,power=1;
    while(power<n+1)
    {
        power=power*2;
        i=i+1;
    }
    return i;
}
void back(int a[],int n)
{
    int i;
    a[0]=n;
    for(i=0;i<log(n)+1;i++)
        a[i+1]=a[i]/2;
}
void main()
{
    int i,m,n;
    int a[11],b[11];
    scanf("%d %d",&m,&n);
    back(a,m);
    back(b,n);

    for(i=0;i<12;i++)
        if(a[log(m)-i]==b[log(n)-i]&&a[log(m)-1-i]!=b[log(n)-i-1])
        {
            printf("%d\n",a[log(m)-i]);
            break;
        }
}


void main()
{
	int a,b,temp;
	scanf("%d %d",&a,&b);
	if(a<b)
	{
		temp=a;
		a=b;
		b=temp;
	}
	while(a!=b)
	{
		do
		{
			a/=2;
		}while(a>b);
		if(a<b)
		{
			temp=a;
			a=b;
			b=temp;
		}
	}
	printf("%d",a);
}


 /* homework2.cpp
 *
 *  Created on: 2012-11-10
 *      Author: Lixurong
 */

int gcd( int m, int n );

int main()
{
	int x, y;
	cin >> x >> y;
	cout << gcd( x, y );
	return 0;
}

int gcd( int m, int n )
{
	if( n>m )
		return gcd( m, n/2 );
	else if( m>n)
		return gcd( m/2, n );
	else
		return m;
}


int min(int x,int y){
    if (x>y) {
        return y;
    }
    else return x;
}
int max(int x,int y){
    if (x<y) {
        return y;
    }
    else return x;
}
int main(){
    int x,y,a,b,logofa;
    cin>>x>>y;
    a=min(x,y);
    b=max(x,y);
    logofa=(log(a)/log(2.0));
    while (b>=(pow(2.0, logofa+1))) {
        b=b/2;
    }
    while (a>0) {
        if (a==b) {
            cout<<a;
            break;
        }
        a=a/2;
        b=b/2;

    }

}


int tree(int x,int y){
	if(x<y)return tree(x,(y-y%2)/2);
	if(x>y)return tree((x-x%2)/2,y);
	if(x==y)return x;
}

int main() {
	int a,b;
	cin>>a>>b;
	cout << tree(a,b) << endl;
	return 0;
}


int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	while(x>=1&&y>=1){
		 if (x==y)
		 {printf("%d",x);
          break;
		 }
		 if(x<y) {
			 while(x<y){
             y=y/2;
			 }
		 }
		 else {
			 while(x>y){
             x=x/2;
			 }
		 }
	}
    return 0;
}


int main(){
int x,y,m;
scanf("%d %d",&x,&y);
m=y;
while(x>=1){
	while(y>=1){
	   if(y==x){
		   printf("%d",y); return 0;
	   }
	   y=y/2;
	   //printf("%d %d\n",x,y);
	}
	x=x/2;
	y=m;
}
return 0;
}


/*
 * 1000062703.cpp
 *
 *  Created on: 2010-11-12
 *      Author: Administrator
 */
int cha(int a,int b){
	if(a>b)
		return(cha(a/2,b));
	if(a<b)
		return(cha(a,b/2));
	if(a==b)
		return a;
}
int main(){
	int x,y;
	cin>>x>>y;
	cout<<cha(x,y)<<endl;
	return 0;
}


int work( int m,int n )
{    while ( m != n )
       { if( m > n ) m /= 2;
        if( m < n  ) n /= 2;
        }
        printf("%d",m);

}
int main()
{   int a , b,m;
    scanf("%d %d",&a,&b);
    work(a,b);

}


int tree(int num,int a)
{
	int back;
	if(a==1)
		back=num;
	else if(tree(num,a-1)%2==0)
		back=tree(num,a-1)/2;
	else back=(tree(num,a-1)-1)/2;
	return back;
}
int main()
{
	int x,y;
	int i,j;
	scanf("%d%d",&x,&y);
	for(i=1;tree(x,i)>0;i++)
		for(j=1;tree(y,j)>0;j++)
			if(tree(x,i)==tree(y,j))
			{
				printf("%d",tree(x,i));
				return 0;
			}
		printf("error");
		return 0;
}


void main()
{
	int x,y,i,count1,count2;
	int a[20],b[20];
	scanf("%d%d",&x,&y);
	for(count1=0;x!=0;count1++)
	{
		a[count1]=x;
		x/=2;
	}
	for(count2=0;y!=0;count2++)
	{
		b[count2]=y;
		y/=2;
	}
	i=0;
	do
	{
		i++;
	}while(a[count1-i]==b[count2-i]);
	printf("%d",a[count1-i+1]);
}


int a,b,c,d,e,h,i,j,k;
int main()
{
	int cha(int a,int b);
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",cha(a,b));

	return 0;
}

int cha(int a,int b)
{
	if(a==b)
		return a;
	int t,q;
	if(a>b)
	{t=a;a=b;b=t;}
	q=b;
	while(a/2!=0)
	{

		while(q/2!=0)
		{

			if(a==q)
				break;
			q/=2;
		}

		if(a==q)
			break;
		a/=2;
		q=b;
	}
	return a;
}


int main() {
	int x, y;
	cin >> x >> y;
	int roadx[15] = {0};
	int roady[15] = {0};
	int c1 = 0, c2 = 0;
	while(1) {
	     roadx[c1] = x;
		 x /= 2;
		 c1++;
		 if(x == 0) break;
	}
	while(1) {
	     roady[c2] = y;
		 y /= 2;
		 c2++;
		 if(y == 0) break;
	}
	int i = 0;
	while(1) {
		if(roadx[c1 - i - 1] != roady[c2 - i - 1]) {
			cout << roadx[c1 - i];
			break;
		}
		if(i == c1 - 1) {
			cout << roadx[0];
			break;
		}
		if(i == c2 - 1) {
			cout << roady[0];
			break;
		}
		i++;
	}
	getchar();
	getchar();
	return 0;
}


int tree(int i,int j)
{
    if(i==j) return i;
    if(i>j)
    {
        return tree(i/2,j);
    }
    if(i<j)
    {
        return tree(j,i);
    }

}
int main()
{
    int i,j;
    cin>>i>>j;
    cout<<tree(i,j);
    return 0;
}


int f(int x ,int y)
{
	if(x==y)return x;
	if(x<y)return f(x,floor(y/2));
	if(x>y)return f(floor(x/2),y);
}
int main()
{
	int n=0;
	int X,Y=0;
cin>>X>>Y;
		cout<<f(X,Y)<<endl;
return 0;
}


//
//  main.cpp
//  HomeWork_11.14.Functions
//  ???
//  Created by ??? on 11/19/12.
//  Copyright (c) 2012 airjcy. All rights reserved.
//

//#include <string>

int findSameNode(int x,int y)
{
    if (x == y) {
        return x;
    }
    else
    {
        if (x > y) {
            return findSameNode(x / 2, y);
        }
        else
        {
            return findSameNode(x, y / 2);
        }
    }
}

int main(int argc, const char * argv[])
{
    int x,y;
    cin >> x >> y;
    cout << findSameNode(x, y);

}


int way(int x,int a[10])
{
	int i=0;
	while(x>0)
	{
		a[i]=x;
		x=x/2;
		i++;
	}
	return(i);
}
int num(int a[10],int x,int b[10],int y)
{
	int p=0,t=0,i,j;
	for(i=x,j=y;i>0&&j>0;i--,j--)
	if(a[i-1]!=b[j-1])
	{
		t=a[i];
		p++;
		break;
	}
	if(p==0)
	if(x>y) t=b[0];
	else t=a[0];
	return(t);
}
int main()
{
	int x,y,a[10],b[10],m,n,t,i,j;
	scanf("%d%d",&x,&y);
	m=way(x,a);
	n=way(y,b);
	t=num(a,m,b,n);
	printf("%d",t);
	return 0;
}


int up(int m)
{
	return (m%2==0)?m/2:(m-1)/2;
}
int main()
{
	int m,n;
	cin>>m>>n;
	int powerm,powern;
	if (m<n) { int temp=m; m=n; n=temp;}
	for (powerm=0;(m>>powerm)>0;powerm++) ;
	for (powern=0;(n>>powern)>0;powern++) ;
	while (powerm>powern)
	{
		m=up(m);
		powerm--;
	}
	while (m!=n)
	{
		m=up(m);
		n=up(n);
	}
	cout<<m<<endl;
	return 0;
}


int main()
{
	int num1[20],num2[20];
	int m,n;
	int len1,len2;
	cin>>m>>n;
	int temp = m;
	for(len1 = 0;temp>=1;len1++){
		num1[len1] = temp;
		temp /=2;
	}
	temp = n;
	for(len2 = 0;temp>=1;len2++){
		num2[len2] = temp;
		temp/= 2;
	}
	int i=1;
	while(num1[len1-i]==num2[len2-i])
		i++;
	cout<<num1[len1-i+1]<<endl;
	return 0;
}


int up(int x) {
	return x/2;
}

int meet(int x, int y) {
	if (x == y)
		return x;

	int depthx = log2(x);
	int depthy = log2(y);
	if (depthx < depthy)
		return meet(x, up(y));
	else if (depthx > depthy)
		return meet(up(x), y);
	else
		return  meet(up(x), up(y));
}

int main() {
	int x, y;
	cin >> x >> y;
	cout << meet(x, y);
}


int refine(int a)
{
  if(a%2==1) return((a-1)/2);
  else return(a/2);
}

int main()
{
  int a,b,i;
  scanf("%d%d",&a,&b);
  while(a!=b)
  {
    if(a>b) a=refine(a);
    else b=refine(b);
  }
  printf("%d",a);
  return 0;
}


int step(int x1,int y1)
{
	if(x1==y1) return x1;
	if(x1>y1)
	{if(x1%2==0) return step(x1/2,y1);
	else return step((x1-1)/2,y1);
	}
	if(x1<y1)
	{if(y1%2==0) return step(x1,y1/2);
	else return step(x1,(y1-1)/2);
	}
}
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<step(x,y)<<endl;
	return 0;
}


int er(int x,int y)
{
	if(x>y)
		return er(x/2,y);
	if(x<y)
		return er(x,y/2);
	if(x==y)
		return x;
}
void main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d",er(x,y));
}


int main()
{//de
	void seq(int m,int*seqm);
	int a,b;
	int seqa[10],seqb[10];
	int i,t;
//in
	scanf("%d%d",&a,&b);
//pro
	seq(a,seqa);
	seq(b,seqb);
//ou
	for(i=0;seqa[i]==seqb[i];i++)t=seqa[i];
	printf("%d",t);
	return 0;
}

void seq(int m,int*seqm)
{
	int i,j;
	int temp[10];
	temp[0]=m;
	for(i=1;m>1;i++)
		temp[i]=m=m/2;
	for(j=i;j>=0;j--)
		seqm[j-1]=temp[i-j];

}


int s(int a,int b)
{
	int p,q;
	if(a>b)
	{
		p=a;q=b;
	}
	else
	{
		p=b;q=a;
	}
	p=p/2;
	if(p==q)return p;
	else s(p,q);
}
int main()
{
	int m,n,re;
	cin>>m>>n;
	if(m==n)cout<<m;
	else
	{
		re=s(m,n);
		   cout<<re<<endl;
	}
	return 0;
}


int result(int x,int y)
{
	int t=0;
	if(x==y)
		t=x;
	else if(x>y)
		t=result(x/2,y);
	else if(x<y)
		t=result(x,y/2);
	return t;
}
void main()
{
	int m=0,n=0;
	scanf("%d%d",&m,&n);
	printf("%d",result(m,n));

}


//
//  Created by Chu-Pan,Wong on Dec 1, 2013.
//  Copyright (c) 2013 ChuPan,Wong. All rights reserved.
//

int routex[1000];
int routey[1000];

int main(int argc, char** argv){
    int x,y;
    cin>>x>>y;
    int nx,ny;
    for (nx=0; x!=1; nx++) {
        routex[nx]=x;
        if (x%2==0) {
            x/=2;
        }
        else{
            x=(x-1)/2;
        }
    }
    for (ny=0; y!=1; ny++) {
        routey[ny]=y;
        if (y%2==0) {
            y/=2;
        }
        else{
            y=(y-1)/2;
        }
    }
    routex[nx]=routey[ny]=1;
    int res;
    while (routex[nx]==routey[ny]) {
        if (nx<0||ny<0) {
            break;
        }
        res = routex[nx];
        nx--; ny--;
    }
    cout<<res<<endl;
    return 0;
}


int main(int argc, char* argv[])
{
	int a,b;
	int temp;
	scanf("%d %d",&a,&b);
	do
	{
		if(a>b)
		  a=a/2;
		if(a<b)
		  b=b/2;
	}while(a!=b);
	printf("%d",a);
	return 0;
}


int zheng(int x,int i)
{
    int j;
    if(i!=1)
    {
        for(j=1;j<i;j++)
            x=x/2;
    }
    return(x);
}
void main()
{
    int zheng(int x,int i);
    int x,y,i,j,temp=0;
    scanf("%d%d",&x,&y);
    if(x==y)
        printf("%d",x);
    else
    {
        for(i=1;i<=10;i++)
        {
            if(temp!=0)
               break;
            for(j=1;j<=10;j++)
            {
                if(zheng(x,i)==zheng(y,j))
                {
                    temp=zheng(y,j);
                    break;
                 }
             }
         }
         printf("%d",temp);
     }
}


int f(int a,int b)
{
	if (a==b) return a;
	if (a<b) return f(b,a);
	if (a%2==0) return f(a/2,b);
	if (a%2==1) return f((a-1)/2,b);
}
int main()
{
	int x,y;
	cin>>x>>y;
	if (x>=y) cout<<f(x,y)<<endl;
	else cout<<f(y,x)<<endl;
	return 0;

}


int find(int,int);
int find(int x,int y)
{
	int a;
	if(x>y) a=find(x/2,y);
	else if(x<y) a=find(x,y/2);
	else a=x;
	return a;
}
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	printf("%d",find(x,y));
	return 0;
}


void main(){
	int x,y;
	int same(int m,int n);
	scanf("%d%d",&x,&y);
	printf("%d",same(x,y));
}

int same(int x,int y){
	while(x!=y){
		if(x>y) x=x/2;
		else y=y/2;
	}
	return x;
}


int P(int a,int b)
{
	if (a==b)
	{
		return a;
	}
	return P(a/2,b/2);
}
int main()
{
	int a,b;
	cin>>a>>b;

	int i,j;
	for (i=0;a>>i!=0;i++);
	for (j=0;b>>j!=0;j++);
	if (i>j)
	{
		a>>=(i-j);
	}
	else
	{
		b>>=(j-i);
	}
	cout<<P(a,b);
	return 0;
}


int col(int x)//?
{
 int i;
 for(i=1;;i++)
 {if(x<=(pow(2,i)-1)) break;}
 return i;
}
int row(int x)//?
{
  int temp;
  temp=col(x);
  return x-pow(2,temp-1)+1;
}
int main()
{
 int a,b;
 scanf("%d %d",&a,&b);
 int cola,rowa,colb,rowb;
 cola=col(a);rowa=row(a);
 colb=col(b);rowb=row(b);
 if(cola>colb)
 {
  while(cola>colb)
  {
   cola--;
   if(rowa%2==0) rowa=rowa/2;
    else rowa=(rowa+1)/2;
  }
 }
 if(cola<colb)
 {
  while(cola<colb)
  {
  colb--;
   if(rowb%2==0) rowb=rowb/2;
    else rowb=(rowb+1)/2;
  }
 }
 while(rowa!=rowb)
 {
  rowa=(rowa+1)/2;
  rowb=(rowb+1)/2;
  cola--;colb--;
 }
 cout<<pow(2,cola-1)+rowa-1;
 return 0;
}


int n,m,i,x,y;
 int function(int n,int m)
 {
	 x=0,y=0;
	 if(n==1||m==1)
		 return 1;
	 if(n==m)
		 return n;
	 else
		{
			if(n%2==0&&m==n+1)
			 return n/2;
			if(m%2==0&&n==m+1)
			 return m/2;
			for(i=m;i>=2;i=i/2)
			{
				y=y+1;
			}
			for(i=n;i>=2;i=i/2)
			{
				x=x+1;
			}
			if(x==y)
				return function(n/2,m/2);
			if(x>y)
				 return function(n/2,m);
			if(x<y)
				return function(n,m/2);
	 }
 }
 int main()
 {
	 cin>>n>>m;
	 cout<<function(n,m)<<endl;
 }


int find(int x , int y)
{
	if (x == y)       //????????
		return x ;
	else if (x > y)
	{
		while (x > y)   //????t???????2t,2t+1??????2?????????
			x = x / 2 ;   //??x<=y????????
		return find(x , y) ;
	}
	else
	{
		while (y > x)  //y??x
			y = y / 2 ;
		return find(x , y) ;
	}
}
int main()
{
	int m , n ;
	cin >> m >> n ;
	cout << find(m , n) ;
	return 0 ;
}


int f1(int x)
{
      int n=1,i,p;
      for(i=0;i<12;i++)
{
      x=x/2;
      n++;
      if(x==1)break;
}
      return n;
}
int f2(int x,int y)
{
     int i;
     for(i=0;i<y;i++)
     x=x/2;
     return x;
}
int main()
{
     int a,b,c,d,e,f;
     cin>>a>>b;
     e=f1(a);
     f=f1(b);
     for(c=0;c<e;c++)
     for(d=0;d<f;d++)
     if(f2(a,c)==f2(b,d))
{
     cout<<f2(a,c);
     c=e+1;
     d=f+1;
}
     return 0;
}


/*
 * trees.cpp
 *
 *  Created on: 2012-11-17
 *      Author: Administrator
 */
int main()
{
	int x=0,y=0;
	cin>>x>>y;
	double row1=0,row2=0;
	row1=ceil(log2((double)(x+1)));
	row2=ceil(log2((double)(y+1)));
	while (row2>row1){
		y=y/2;
		row2=ceil(log2((double)(y+1)));
	}
	while (row1>row2){
			x=x/2;
			row1=ceil(log2((double)(x+1)));
		}
	while (x!=y){
		x=x/2;
		y=y/2;
	}
	cout <<x<<endl;
	return 0;
}


int main()
{
	int a,b;
	void search(int,int);
	scanf("%d %d",&a,&b);
	search(a,b);
}
void search(int a,int b)
{
	if(a==b) printf("%d",a);
	else if(a>b)  search(a/2,b);
	else search(a,b/2);
}


/*
 * pr8.cpp
 *
 *  Created on: 2011-11-15
 *      Author: Gan Hua
 */
int main()
{
	int x,y,i=1,min,max;
	cin>>x>>y;
	min=x;max=y;
	if(y<x)
		{min=y;max=x;}
	for(min=min;min>0;min=min/2)
		if(i)
		for(max=max;max>=min;max=max/2)
			if(max==min)
				{cout<<max;i=0;}}


int step(int,int);
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<step(x,y)<<endl;
}
int step(int a , int b )
{
	if ( a > b )
	{
		if ( a % 2 == 0 )
			return step( a/2 , b );
		else
			return step( (a - 1) / 2 , b );
	}
	else if ( a < b )
	{
		if ( b % 2 == 0 )
			return step( a , b/2 );
		else
			return step( a , ( b-1) / 2 );
	}
	else
		return a;
}


int search (int n)
{
	return n/2;
}
int main ()
{
	int x, y;
	scanf("%d%d", &x, &y);
	while (x!=y) {
		if (x>y)
			x=search(x);
		else if(x<y)
			y=search(y);
	}
	printf("%d", x);
	return 0;
}


int toup (int m)
{int l;l=m/2;return l;}

int main(){int i,j;
int a[300],b[300],ac=0,bc=0,xun,h;
scanf("%d%d",&i,&j);

a[0]=i;b[0]=j;
for(xun=1;;xun++){if(a[xun-1]!=1){a[xun]=toup(a[xun-1]);ac=ac+1;}else{break;}                   }
for(xun=1;;xun++){if(b[xun-1]!=1){b[xun]=toup(b[xun-1]);bc=bc+1;}else{break;}                   }

for(h=1;;h++){if(a[ac-h]!=b[bc-h]){ printf("%d",a[ac-h+1]);break;}        }
return 0;}


int main(){
	int x,y;
	cin>>x>>y;
	while(x!=y){
	if(x>y)x=x/2;
	else y=y/2;
	}
	if(x==y)cout<<x<<endl;
	return 0;
}


void main()
{

	int x,y,i,j,num1,num2;
	int xline[11],yline[11];

	scanf("%d%d",&x,&y);

	xline[0]=x;
	yline[0]=y;

	i=1;
	while (x>1)
	{
		x=x/2;
        xline[i]=x;
		i=i+1;
	}
    num1=i-1;

	i=1;
	while(y>1)
	{
		y=y/2;
		yline[i]=y;
		i=i+1;
	}
	num2=i-1;

	for(i=0;i<=num1;i++)
	{
		for(j=0;j<=num2;j++)
			if (xline[i]==yline[j])
			{
				printf("%d\n", xline[i]);
				i=num1+1;
			}
	}
}


int main(int argc, char* argv[])
{
	int x,y;
	scanf("%d%d",&x,&y);
	while(x!=y)
	{
	if(x>y)
		x/=2;
	else
		y/=2;
	}
	printf("%d",x);

	return 0;
}


void main()
{
	int f1(int n,int m);
	int m,n;
	scanf("%d%d",&n,&m);
	printf("%d\n",f1(n,m));
}

int f1(int n,int m)
{
	if(n==m)
		return n;
	else if(n>m)
	{
		if(n%2==0)
			return f1(n/2,m);
		else
			return f1((n-1)/2,m);
	}
	else
	{
		if(m%2==0)
			return f1(n,m/2);
		else
			return f1(n,(m-1)/2);
	}
}


/*
 *  ???.cpp
 *  Created on: 2012-11-19
 *  Author:???
 */
int f(int a, int b) {
	if (a == b)
		return a;
	if (a > b) {
		a = a % 2 == 0 ? a / 2 : (a - 1) / 2;
		return f(a, b);
	} else {
		b = b % 2 == 0 ? b / 2 : (b - 1) / 2;
		return f(a, b);
	}
}
int main() {
	int a, b;
	cin >> a >> b;
	cout << f(a, b) << endl;
	return 0;
}


int main()
{
	int m,n;
	scanf("%d %d",&m,&n);
	int word1[500],word2[500];
	int i,j,num,log1,log2;
	word1[0]=m;
	word2[0]=n;
	i=j=1;
	while(m!=1)
	{
		word1[i]=m/2;
		i+=1;
		m=m/2;
		//printf(" %d %d ",word1[i],m);
	}
	//printf("%d",m);
	log1=i-1;
	while(n!=1)
	{
		word2[j]=n/2;
		j+=1;
		n=n/2;
		//printf(" %d  %d ",word2[i],n);
	}
	log2=j-1;
	int word;
	word=0;
	for(i=0;i<=log1;i++)
	{
		for(j=0;j<=log2;j++)
		{
			if(word1[i]==word2[j])
			{
				//printf("\n");
				printf("%d",word1[i]);
				//printf("\n");
				word++;
				break;
			}
		}
		if(word!=0)
		    break;
	}
	return 0;
}


void tree(int p,int k,int c[])
{
	c[k]=p;
	if(c[k]==1)
		return;
	else
	{
		tree(c[k]/2,k+1,c);
	}
}

void main()
{
	int x,y,i,j,a[12]={0},b[12]={0};
	scanf("%d%d",&x,&y);
	tree(x,0,a);
	tree(y,0,b);
	for(i=j=0;;)
	{
		if(a[i]>b[j])
		{
			i++;
			continue;
		}
		if(b[j]>a[i])
		{
			j++;
			continue;
		}
		if(a[i]==b[j])
			break;
	}
	printf("%d\n",a[i]);
}


int main()
{
  int x,y;
  cin>>x>>y;

  int tree(int,int);
  cout<<tree(x,y);

}

int tree(int x,int y)
{
	while(x!=y)

	{
	      if(x>y)
			  x=x/2;
		  else
			  y=y/2;
	}

	return x;

}


void half(int x,int y)
{
	if(x==y)
		cout<<x<<endl;
	else if(x>y)
	{
		x=x/2;
		half(x,y);
	}
	else
	{
		y=y/2;
		half(x,y);
	}
}
int main()
{
	int x,y;
	cin>>x>>y;
	half(x,y);
	return 0;
}


int f(int x,int y);
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<f(x,y);
}
int f(int x,int y)
{
	if(x==y) return x;
	if(x>y)
	{
		x=x/2;
		return f(x,y);
	}
		if(x<y)
		{
			y=y/2;
			return f(x,y);
		}
}


int two(int n)
{
	int m=1,i;

	for(i=0;i<=n;i++)
	{
		if(i==0)
		{
			m=1;
		}
		else
		m=m*2;
	}
	return(m);
}

int main()
{
	int two(int n);
    int zhao(int x,int y,int row1,int flag);
	int x,y,i,row1,row2,flag=0,t;
	scanf("%d %d",&x,&y);
	for(i=0;i<=10;i++)
	{
		if(x==two(i))
		{
			row1=i;

		}
		else
		{
			if(x>two(i)&&x<two(i+1))
			{
				row1=i;

			}
		}
	}

	for(i=0;i<=10;i++)
	{
		if(y==two(i))
		{
			row2=i;

		}
		else
		{
			if(y>two(i)&&y<two(i+1))
			{
				row2=i;

			}
		}
	}
    if(x==y) printf("%d",x);
	else if(x>y)
	{

		t=zhao(x,y,row1,flag);
			if(t==0)
			{
				for(i=1;i<=row2;i++)
				{
				if(y%2==0)
				{
					y=y/2;
				}
				else y=(y-1)/2;

				t=zhao(x,y,row1,flag);
				if(t==1)
				{
					break;
				}
			}
			}

	}
	else if(y>x)
	{
		t=zhao(y,x,row2,flag);
			if(flag==0)
			{
				for(i=1;i<=row1;i++)
				{
				if(x%2==0)
				{
					x=x/2;
				}
				else x=(x-1)/2;
				t=zhao(y,x,row2,flag);
				if(t==1)
				break;
			}
			}

	}

	return 0;
}

int zhao(int x,int y,int row1,int flag)
{
	int i;
	for(i=1;i<=row1;i++)
		{
			if(x%2==0)
			{
				x=x/2;
			}
			else x=(x-1)/2;
			if(x==y)
			{
				printf("%d",x);
				flag=1;
				break;

			}
			else continue;
	}
	return (flag);
}


void fuck(int x,int y){
	int temp;
	if(x==y)
		cout<<x;
	else{
		if(y<x) {temp=x;x=y;y=temp;}
	fuck(x,y/2);
	}
}

int main(){
	int x,y;
	cin>>x>>y;
	fuck(x,y);
	return 0;
}


int main()
{
	int exist=0,addressx[10]={0},addressy[10]={0},h,k,x,y,i=0,j=0;
	scanf("%d%d",&x,&y);
	while (x>=1)
	{
      addressx[i]=x;

	  x=x/2;
	  i+=1;
	}

	while (y>=1)
	{
		addressy[j]=y;

		y=y/2;
		j+=1;
	}

	for (h=0;h<=i-1;h++)
	{
		for (k=0;k<=j-1;k++)
		{
			if (addressx[h]==addressy[k])
			{
				printf("%d",addressx[h]);
				exist=1;
				break;
			}
		}
		if(exist==1)
			break;

	}
}


int main()
{
	int n,m;
	cin>>n>>m;
	int f(int,int);
	cout<<f(n,m)<<endl;
	return 0;
}
int f(int a,int b)
{
	int cr;
	if(a==b) cr=a;
	else if(a>b) cr=f(a/2,b);
	else cr=f(a,b/2);
	return cr;
}


int main()
{
	int c(int x,int y);
	int x,y;//???x?y
	cin>>x>>y;
	cout<<c(x,y)<<endl;
return 0;
}

int c(int x,int y)//?????
{
	int z;
	if(x==y)//???????
		z=x;
	if(x>y)
		z=c(x/2,y);//???????
	if(y>x)
		z=c(x,y/2);
	return z;
}


int main(int argc, char* argv[])
{
	int t,x,y,a;
	scanf("%d %d",&x,&y);
	if(x==1||y==1) printf("1");
	else if(x==y) printf("%d",x);
	else if(x!=y)
	{
		if(y>x)
		{
			a=x;
			x=y;
			y=a;
		}
			do
			{
				x/=2;
				if(x<y)
				{
					t=x;
					x=y;
					y=t;
				}
			}while(x!=y);

		printf("%d",x);
	}

	return 0;
}


int main()
{
    int x,y;
    cin>>x>>y;int t1=x,t2=y;
    int xx[12],yy[12];int k=0,kk=0;
    while(x>0)
    {
              xx[k++]=x;
              x=x/2;
    }
    while(y>0)
    {
              yy[kk++]=y;
              y=y/2;
    }
    int ans=0;
    for(int i=0;i<k;i++)
    {
            for(int j=0;j<kk;j++)
             if(xx[i]==yy[j])
              ans=xx[i];
              if(ans!=0)
              break;
    }
    if(t1==t2) ans=t1;
    cout<<ans<<endl;
    return 0;
}


int main(){
  int i,j;
  for (cin>>i>>j;i!=j;){
    while (i>j) i/=2;
    while (j>i) j/=2;
  }
  cout<<j<<endl;
}


/*
 * 1.cpp
 *
 *  Created on: 2011-11-14
 *      Author: wangwenxia1963
 */
int main()
{
	int x,y,a,b,i,j;
	cin>>x>>y;
	for(i=1;x/i>0;i=i*2)
		a=x%i;
	for(j=1;y/j>0;j=j*2)
		b=y%j;
	i=i/2;j=j/2;
	if(i>j)
		x=x*j/i;
	else y=y*i/j;
	while(x!=y)
		{
		x=x/2;
		y=y/2;
		}
	cout<<x;

}


void main()
{
    int x,y;
	scanf("%d %d",&x,&y);
    while(x!=y)
	{
	if(x<y)
    y=y/2;
	else if(x>y)
	x=x/2;
	}
	printf("%d\n",x);
}


int comp(const void *c,const void *d)
{
	return *(int *)c-*(int *)d;
}
int main(void)
{
	int i=0,j=0,k,x,y,x1,y1;
	int a[1001];
	int b[1001];
	scanf("%d%d",&x,&y);
	x1=x;y1=y;
	while(x>=1)
	{
		a[i++]=x;
		x/=2;
	}
	while(y>=1)
	{
		b[j++]=y;
		y/=2;
	}
	qsort(a,i,sizeof(a[0]),comp);
	qsort(b,j,sizeof(b[0]),comp);
	for(i=0;;i++)
	{
		if(a[i]==b[i])
		    k=a[i];
		else
		    break;
	}
	if(x1==y1)
		printf("%d",x1);
	else
		printf("%d",k);
	return 0;
}


void main()
{
	int m,n,j,i;
	scanf("%d%d",&m,&n);
	if(m==n)
		printf("%d",m);
	else if(m==1||n==1)
		printf("1");
	else
	{
	   for(i=0;m>=1;i++)
	   {
		   for(j=0;n>m;j++)
		   {
			   n=n/2;
		   }
           if(n!=m)
		   {
			   m=m/2;
	   		  continue;
		   }
		   if(n==m)
    		   break;
	   }
	   printf("%d\n",m);
	 }
}


int main()
{
	int a,b,i,t;
	scanf("%d%d",&a,&b);
	if(a==b)printf("%d",a);
	else {
		if(a<b){
			t=a;
			a=b;
			b=t;
		}
		while(a/2!=b){
			a=a/2;
			if(a/2<b){
				t=a;
				a=b;
				b=t;
		}
		}
	printf("%d",b);
	}
}


int answer(int a , int b)
{
	if(a==b)
	{
		return a;
	}
	else if(a>b)
	{
		return answer(a/2,b);
	}
	else
	{
		return answer(a,b/2);
	}
}
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<answer(x,y)<<endl;
	return 0;
}


//
//  main.cpp
//  ???
//
//  Created by ???? on 13-11-22.
//  Copyright (c) 2013? ????. All rights reserved.
//

int f(int x)
{
    return x/2;
}

int main()
{
    int a,b;
    cin>>a>>b;
    while(1)
    {
        if(a>b)a=f(a);
        else if(b>a)b=f(b);
        else if(a==b){cout<<a<<endl;break;}
    }

    return 0;
}


int main(int argc, char* argv[])
{
	int x,y,z;
	scanf("%d %d",&x,&y);
	while(x!=y)
	{
		if(x<y)
		{
			z=x;
			x=y;
			y=z;
		}
		x/=2;
		if(x==y)
		{
			break;
		}
	}
	printf("%d",x);
	return 0;
}


void check(int x,int y)
{
	if(x==y)
		printf("%d",x);
	else
	{
		if(x>y&&x/2>=y/2)
			check(x/2,y);
		if(x<y&&x/2<=y/2)
			check(x,y/2);
	}
}
main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	check(x,y);
}


int main ()
{
  int a,b;
  scanf("%d%d",&a,&b);
  do
  {
     if(a==b)
      {
          break;
      }
      if(a>b)
      {
          a=a/2;
      }
      else
       {
          b=b/2;
      }

  }
  while(1);
  printf("%d",a);
  return 0;
}


void main()
{
  int i,m,n,temp;
  scanf("%d%d",&m,&n);
  if(m<n)
  {
    temp=m;
	m=n;
	n=temp;
  }
  if(m==n)  printf("%d\n",m);
  else
  {
  for(;;)
  {
    if(m/2==n)
	{
		printf("%d\n",n);
		break;
	}
	else
	{
	  if(m/2>n)  m/=2;
	  else
	  {
	    temp=n;
		n=m/2;
		m=temp;
	  }
	}
  }
  }
}


int main() {
	int xpath[100],ypath[100];
		int xi=0,yi=0;
		cin>>xpath[0]>>ypath[0];
		while(xpath[xi]!=1)
		{
			xpath[xi+1]=xpath[xi]/2;
			xi++;
		}

		while(ypath[yi]!=1)
		{
			ypath[yi+1]=ypath[yi]/2;
			yi++;
		}
		while(xi>=0&&yi>=0)
		{
			if(xpath[xi]!=ypath[yi])
			{
				cout<<xpath[xi+1]<<endl;
				return 0;
			}
			xi--;
			yi--;
		}
		cout<<(xi<0?xpath[0]:ypath[0])<<endl;
		return 0;
}


int main()
{
    int x,y,ercha(int x,int y);
    scanf("%d %d",&x,&y);
    printf("%d",ercha(x,y));
    return 0;
}

int ercha(int x,int y)
{
          if(x==y) return x;
          else
          {
              if(x>y)
              {
              x=x/2;
              }
              else
              {
              y=y/2;
              }
              ercha(x,y);
          }
}


int luo(int x,int y)
{
    int r1,r2,c;
	if(x==y)
		return x;
	else
	{
		r1=log((double)x)/(log(2.0));
	    r2=log((double)y)/(log(2.0));
	    if(r1>=r2)
		{
			x=x/2;
		    luo(x,y);
		}
		else
		{
			y=y/2;
			luo(x,y);
		}
	}
}
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	printf("%d",luo(x,y));

	return 0;
}


void main()
{
	void change(int *p1,int *p2);
    int a,b;
	scanf("%d %d",&a,&b);
	while(a!=b)
	{
		if(a>b)
		{
			change(&a,&b);
		}
		b=b/2;
	}
	printf("%d\n",a);
}

void change(int *p1,int *p2)
{
	int temp;
	temp=*p1;
	*p1=*p2;
	*p2=temp;
}


int main()
{
    int x,y,x0,y0,result,flag=0;

    scanf("%d %d",&x,&y);

    x0=x;y0=y;
    for (x=x0;x>=1;x/=2)
        for (y=y0;y>=1;y/=2)
            if (x==y&&flag==0)
            {
               result=x;
               flag=1;
            }

    printf("%d\n",result);
    getchar();getchar();

    return 0;

}


int  common(int x,int y);
int main()
{
	int x,y;
	while(cin>>x>>y)
	{
		cout<<common(x,y);
	}
	return 0;
}
int common(int x,int y)
{
	if(x==y)
	return x;
	else
	{
		int p;
		if(x>y)
		return common((int)x/2,y);
		else
		return common(x,(int)y/2);
	}
}


int k=0;
void findrouteA(int *ay,int n,int m);

int main()
{
	int a,b;
	int ay[10]={0},by[10]={0};//????a,b???
	int i,j;
	int end1,end2;
	int an,am,bn,bm;//??a,b?????????
	scanf("%d%d",&a,&b);
	for(i=1,j=1;j<a+1;i++,j+=j);
	an=i-1;
	am=a-( int )pow(2,i-2)+1;

	for(i=1,j=1;j<b+1;i++,j+=j);
	bn=i-1;
	bm=b-( int )pow(2,i-2)+1;//you cuo

	findrouteA(ay,an,am);
	end1=k-1;
	k=0;
	findrouteA(by,bn,bm);
	end2=k-1;

	for(end1,end2;ay[end1]==by[end2];end1--,end2--);
	printf("%d",ay[end1+1]);
	return 0;
}
void findrouteA(int *ay,int n,int m)
{
	if(n==1)
		ay[k++]=1;
	else
	{
		ay[k++]=( int )pow(2,n-1)-1+m;
		findrouteA(ay,n-1,( int )(m+1)/2);
	}
}


int main()
{
	int m,n,an;
	scanf("%d %d",&m,&n);
	an=f(m,n);
	printf("%d",an);

}
int f(int a,int b)
{
	int w;
	if(a==b)
		w=a;
	if(a>b)
		w=f(a/2,b);
	if(a<b)
		w=f(a,b/2);
	return w;

}


int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	while(x!=y)
	{
		if(x>=2*y)
		{
			x=x/2;
		}
		else if(y>=2*x)
		{
			y=y/2;
		}
		else
		{
			x=x/2;
			y=y/2;
		}
	}
	printf("%d",x);
	return 0;
}


int t,m,n,i,j,k,xx,x1,x2,x,y,s,n0;

void init(int a[],int b[])
{    freopen("tt.in","r",stdin);
     scanf("%d%d",&m,&n);
	 for (i=1;i<=m;i++)

			 scanf("%d",&a[i]);
	 for (i=1;i<=n;i++)

			 scanf("%d",&b[i]);

	 }

void output(int a[],int k)
{
 int i;
	freopen("tt.out","w",stdout);
	for(i=1;i<=k;i++) if (i==1) printf("%d",a[i]); else printf(" %d",a[i]);
}
 void proce(int x,int y)
{
	if (x==y) printf("%d\n",x);
	else
	if (x>y) proce(x/2,y);
	else
	proce(x,y/2);

}

int main()
{
//freopen("tt.in","r",stdin);
//freopen("tt.out","w",stdout);
	scanf("%d%d",&x,&y);

	proce(x,y);

return 0;
}


int find(int,int);
int main()
{
    int ans;
    int x,y;
    cin>>x>>y;
    ans=find(x,y);
    cout<<ans<<endl;
    return 0;
}
int find(int x,int y)
{
    if(x==y) return x;
    if(x>y) return find(y,x);
    else return find(x,y/2);
}


int com(int x, int y)
{
	int t;
	if(x==y) t=x;
	else
		t=(x>y)?com(x/2,y):com(x,y/2);
	return t;
}
void main ()
{
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n",com(x,y));
}


int main(int argc, char* argv[])
{
	int a, b, c, d;
	scanf("%d %d",&a,&b);
	c=1;
	while(c==1)
	{
		if(a>b)
			a=a/2;
		if(a<b)
			b=b/2;
		if(a==b)
		{
			c=0;
			printf("%d",a);
		}
	}
	return 0;
}


int f(int n,int m)
{
	if(n==m)
		return n;
	else
	{
		if(n/2>m)
			return f(n/2,m);
		else
			return f(m,n/2);
	}
}
int main()
{
    int n,m;
	cin>>n>>m;
	if(n<m)
	{
			n = n^m;
			m = n^m;
			n = n^m;
	}

	cout<<f(n,m)<<endl;
    return 0;
}


int main()
{
    int x,y;
    int p;
    int a[10];
    int b[10];
    int i=0,j=0,k,m;
    scanf("%d%d",&x,&y);
    do
    {
    if (x>y)
    {
        x=x/2;
    }
    else
    if (y>x)
    {
        y=y/2;
    }
    if(x==y)
        {
            printf("%d",x);
        }
    }
    while(x!=y);

    return 0;
}


int I=0;

int root(int *a,int n)
{
	*(a+I)=n;
	I++;
	if(n!=1){
		if(n%2==0)
			root( a,n/2 );
		else
			root( a,(n-1)/2 );
	}
	return I;
}

void main()
{
	int a0,b0,a[MAX],b[MAX],m,n,i,j,flag=0;
	scanf("%d%d",&a0,&b0);
	m=root(a,a0);
	I=0;
	n=root(b,b0);

	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if( *(a+i)==*(b+j) ){
				printf("%d\n",*(a+i));
				flag=1;
				break;
			}
		}
		if(flag)
			break;
	}
}


f(int m,int n)
{
  if (m<n)
    return f(m,n/2);
  else if (m>n)
    return f(m/2,n);
  else
  return m;
}

int main(int argc, char *argv[])
{
  int x,y;
  scanf("%d%d",&x,&y);
  printf("%d",f(x,y));
  return 0;
}


int f(int a,int b)
{

	if(a==b)
		return a;
	else if(a>b)
		 return f(a/2,b);
	else if(a<b)
		 return f(a,b/2);

}

int main()
{
	int x,y;
	cin>>x>>y;
	f(x,y);

	cout<<f(x,y)<<endl;

	return 0;
}


int f(int a,int b)
{
	if(a==b) return a;
	else if(a>b) {a=a/2;return f(a,b);}
	else {b=b/2;return f(a,b);}
}
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<f(x,y)<<endl;
    return 0;
}


int main(int argc, char* argv[])
{

int a,b,c;
int i;
scanf("%d %d",&a,&b);

for (i=1;i<=50;i++)
{
	if(a>b)
	{ c=a;
	  a=b;
	  b=c;}
	else if(b>a)
	 b=b/2;
	else
	{printf("%d",a);
	break;}
}
return 0;
}


void common(int a,int b);
void main()
{
    int x,y;
	scanf("%d %d",&x,&y);
	common(x,y);
}
void common(int a,int b)
{
	if(a==b) printf("%d",a);
    else if((a/2)==b) printf("%d",b);
    else if(a==(b/2)) printf("%d",a);
    else if(a/2>b) common(a/2,b);
	else if(b/2>a) common(a,b/2);
    else common(a/2,b/2);
}


struct tree
{
	struct tree *up;
	int num;
};
struct tree *MLC,*ptree;
int a[500],b[500];

int main()
{
	int x,y,i=1,j,p,q,miao,woofoo=0;
	MLC=(struct tree *)malloc(MAXNUM*sizeof(struct tree));
	for(ptree=MLC;ptree<MLC+1000;ptree++)
	{
		ptree->num=i;
		//printf("%d\n",ptree->num);
		(ptree+i)->up=ptree;
		(ptree+i+1)->up=ptree;
		i++;
	}
	scanf("%d%d",&x,&y);
	ptree=MLC;
	ptree=ptree+x-1;
	i=0;
	do
	{
		a[i]=ptree->num;
		//printf("%d\n",a[i]);
		ptree=ptree->up;
		i++;
	}while(a[i-1]!=1);
	ptree=MLC+y-1;
	j=0;
	do
	{
		b[j]=ptree->num;
		//printf("%d\n",b[j]);
		ptree=ptree->up;
		j++;
	}while(b[j-1]!=1);
	/*for(p=i;p>0;p--)
		printf("%d\n",a[p]);*/
	for(p=0;p<i;p++)
	{
		miao=0;
		for(q=0;q<j;q++)
		{
			if(a[p]==b[q])
			{
				miao++;
				break;
			}
		}
		if(miao==1)
		{
			printf("%d\n",a[p]);
			break;
		}
	}
	return 0;
}


/*
 * erchasu.cpp
 *
 *  Created on: 2012-11-26
 *      Author: Justin
 */

int main(){
          int x,y;
	cin>>x>>y;
		while(x!=y){
		if(x>y){
			x=x/2;
		}
		else{y=y/2;}
	}
	cout<<x;
}


int binTree(int a, int b)
{
	if(a == b)
         {
		return a;
	}
	if(a > b)
         {
		binTree(a / 2, b);
	}
         else
         {
		binTree(a, b / 2);
	}
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	printf("%d", binTree(n, m));
}


int main()
{
	int x,y,t;
	scanf("%d %d",&x,&y);
	if(x==1||y==1)
	{
		printf("1\n");
	}
	else
	{if(x==y)
	{printf("%d\n",x);}
	else
	{do
	{if(x>y)
	{
		t=x;
		x=y;
		y=t;
	}
	y=y/2;
	}while(x!=y);
	printf("%d\n",y);
	}
	}

	return 0;
}


int function( int x , int y );
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<function( x , y )<<endl;
}

int function( int x , int y )
{
	if( x==y )
	{
		return ( x );
	}
	else if( x > y )
	{
		if( x%2==0 )
		{
			return( function( x/2 , y ) );
		}
		else
		{
			return( function( (x-1)/2 , y ) );
		}
	}
	else
	{
		if( y%2==0 )
		{
			return( function( x , y/2 ) );
		}
		else
		{
			return( function( x , (y-1)/2 ) );
		}
	}
}


void main()
{
	int m,n,x;
	scanf("%d%d",&m,&n);
	x=n;
	while(m>=1)
	{
		n=x;
		while(n>=1)
		{
		  if(m==n)
		  {
			printf("%d\n",m);
			break;
		  }
		  n=n/2;
		}
		if(m==n) break;
		m=m/2;
	}
}


int main(){
int a,b;
scanf("%d%d",&a,&b);
while(a!=b)
{
if(a>b)a/=2;
else b/=2;
}
printf("%d",a);
}


int erchashu(int a[1000],int n)
{
	int i;
	a[0]=n;
	if(n!=1)
	{
		for(i=1;;i++)
		{
			a[i]=a[i-1]/2;
		    if(a[i]==1)break;
		}
	    return i;
	}
	else
		return 0;
}

void main()
{
	int a,b,A[1000],B[1000],m,n,p,q;
	scanf("%d %d",&a,&b);
	m=erchashu(A,a);
	n=erchashu(B,b);
	{
	    if(A[0]==B[0])
		{
		    printf("%d\n",A[0]);
		}

		else
		{
			for(p=m,q=n; ;p--,q--)
			{
				if(A[p]==B[q])
					continue;
		        else if(A[p]!=B[q])
				{
					printf("%d\n",A[p+1]);
			        break;
				}

			}
		}
	}
}


int step(int a,int b)
{
	int i,n;
	if(a==b)return a;
	else
	{
	    for(i=1;pow(2,i)-1<b;i++){}n=i;
	    b=pow(2,n-2)+floor((b-pow(2,n-1))/2);
		if(a<=b)step(a,b);
		else step(b,a);
	}
}

int main()
{
	int x1,x2;
	scanf("%d%d",&x1,&x2);
	if(x1<=x2)printf("%d\n",step(x1,x2));
	else printf("%d\n",step(x2,x1));
	return 0;
}


int len(int x)
{
	int i,k=0;
	for(i=1;i<=10;i++)
	{
		if(x!=0)
		{
			x=(x-x%2)/2;
			k+=1;
		}
		else break;
	}
	return k;
}
int ch(int x,int y)
{
	int i,n;
	n=len(x);
	for(i=1;i<=n-y;i++)
	{
		x=(x-x%2)/2;
	}
	return x;
}
int main()
{
	int x,y,m,n,i,a,s,same;
	scanf("%d %d",&x,&y);
	m=len(x);
	n=len(y);
	if(m>n)a=n;
	else a=m;
	for(i=a;i>=1;i--)
	{
		x=ch(x,i);
		y=ch(y,i);
		if(x==y)
		{
			printf("%d",x);
			break;
		}
	}
	return 0;
}


int i,n,k;

void work(int p,int u)
{
	if (u==1) {cout<<p;exit (0);}
	if (p%(n-1)==0)
  if((n*p/(n-1)+k)%n==k)
	 work(n*p/(n-1)+k,u-1);
}
int main()
{
	cin>>n>>k;
	while (n!=k)
					if (n>k) n=n>>1; else k=k>>1;
  cout<<n;
	return 0;
}


int main()
{
	int a,b;
	cin>>a>>b;
	void cha_pri(int,int);
	if(a!=b)
		cha_pri(a,b);
	else cout<<a<<endl;

	return 0;
}

void cha_pri(int m,int n)
{
	void cha_pri(int,int);
	if(m>n)
	{
		m/=2;
		if(m==n)
			cout<<m;
		else cha_pri(m,n);
	}
	else if(m<n)
	{
		n/=2;
		if(m==n)
			cout<<m;
		else cha_pri(m,n);
	}
	else return;
}


int main()
{
  int p,q;
  void y(int n,int m);
  scanf("%d%d",&q,&p);
  y(p,q);
  return 0;
}
void y(int n,int m)
{
  if(n==m)
  printf("%d",n);
  else if(m>n)
  {
    if(m>=(2*n))
      y(m/2,n);
     else if(m<(2*n))
      y(m/2,n/2);
   }
   else
      y(m,n);
 }


int number(int n)
{
	int i,k=1;
	for(i=1;;i++)
	{
		k*=2;
		if(n<k)
			break;
	}
	return i;
}
void array(int a[],int number,int n)
{
	a[number]=n;
	int l=number;
	int i;
	for(i=1;i<l;i++)
	{
		if(n%2==0)
			n/=2;
		else
			n=(n-1)/2;
		number-=1;
		a[number]=n;
	}
}

void main()
{
	int m,n;
	scanf("%d%d",&m,&n);
	int m1,n1,k=0;

	m1=number(m);
	n1=number(n);
	int a[100]={0},b[100]={0};
	array(a,m1,m);
	array(b,n1,n);
	int i,j;
	for(i=m1;i>=1;i--)
	{
		for(j=n1;j>=1;j--)
		{
			if(a[i]==b[j])
			{
				printf("%d\n",a[i]);
				k=1;
				break;
			}
		}
		if(k)
			break;
	}
}


int choose(int x,int y)
{
	if(x==y)return x;
	if(x>y)return choose(x/2,y);
	else return choose(x,y/2);
}
void main()
{
	int choose(int x,int y);
	int m,n,k;
	scanf("%d%d",&m,&n);
	k=choose(m,n);
	printf("%d\n",k);
}


int main()
{
	int x, y;
	scanf("%d%d",&x,&y);
	int xroute[20],yroute[20];
	xroute[0]=x;
	yroute[0]=y;
	int i, j, a, b;
	for(i=1; i<20; i++)
	{
		if(xroute[i-1]==1) break;
		if(xroute[i-1]%2==0) xroute[i]=xroute[i-1]/2;
		else xroute[i]=(xroute[i-1]-1)/2;
	}
	a=i-1;
	for(i=1; i<20; i++)
	{
		if(yroute[i-1]==1) break;
		if(yroute[i-1]%2==0) yroute[i]=yroute[i-1]/2;
		else yroute[i]=(yroute[i-1]-1)/2;
	}
	b=i-1;
	for(i=0; i<=a; i++)
	{
		for(j=0; j<=b; j++)
		{
			if(xroute[i]==yroute[j])
			{
				printf("%d\n",xroute[i]);
				return 1;
			}
		}
	}
	return 0;
}


int main()
{
	int common(int x,int y);
	int m,n;
	cin>>m>>n;
	cout<<common(m,n)<<endl;
	return 0;
}

int common(int x,int y)
{
	if(x==y){
		return x;
	}
	if(x>y){
		return common(x/2,y);
	}
	if(x<y){
		return common(x,y/2);
	}
}


void find(int x,int y)
{
	if(x==y)
		printf("%d\n",x);
	else if(x>y)
		find(x/2,y);
	else
		find(x,y/2);
}
void main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	find(x,y);
}


int main()
{
	int ec(int a,int b);     //?? ec????
	int x,y;
	cin>>x>>y;
	cout<<ec(x,y);
	return 0;
}
int ec(int a,int b)
{
	if(a==b)
		return a;           //??????
	if(a>b)
	{	int t=a;
		a=b;
		b=t;
	}
	return(ec(a,b/2));         //????
}


int Sort(int a,int b)
{
	int i;
	if (a == b)
		return a;
	else if (a>b)
		Sort(a/2,b);
	else
		Sort(a,b/2);
}

int main()
{
	int x,y,xi;
	cin >> x >> y;
	cout << Sort (x,y) << endl;
	return 0;
}


int k;
void tree(int m, int n)
{
	if (m == n)
		k = m; // ??
	else if (m > n)
		tree(m / 2, n);
	else if (m < n)
		tree(m, n / 2); // ??
}
int main()
{
	int x, y;
	cin >> x >> y;
	tree(x , y);
	cout << k;
	return 0;
}


void main()
{
	int f(int m,int n);
	int d,M,N;
	scanf("%d%d",&M,&N);
	printf("%d",f(M,N));
}
int f(int m,int n)
{
	int a;
	if (m<n)
	{
		a=m;
		m=n;
		n=a;
	}
	if (m==n)
		return m;
	else
		return f(m/2,n);
}


int A[10]={0},B[10]={0};
int main()
{
	int x,y,*pt1,*pt2,number1=0,number2=0,flag=0;
	pt1=A;
	pt2=B;
	scanf("%d%d",&x,&y);
	while(x!=0)
	{
		*pt1=x;
		x=x/2;
		pt1++;
		number1++;
	}
	while(y!=0)
	{
		*pt2=y;
		y=y/2;
		pt2++;
		number2++;
	}
	for(pt1=A;pt1<A+number1;pt1++)
	{
		for(pt2=B;pt2<B+number2;pt2++)
		{
			if(*pt1==*pt2)
			{
				printf("%d",*pt1);
				flag=1;
				break;
			}
		}
		if(flag==1)
			break;
	}
	return 0;
}


int main()
{
	int route(int x, int y);//????
	int x,y;
	cin>>x>>y;
	cout<<route(x,y);
	return 0;
}

int route(int x, int y)
{
	if(x==y)
		return x;
	else
	{
		if(x/2>=y)
			return route(x/2,y);
		else if(x<=y/2)
			return route(x,y/2);
		else
			return route(x/2,y/2);
	}
}


void main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	int i=x,j=y;
	while(i!=0&&j!=0)
	{
		if(i==j)
			break;
		else if(i>j)
			i=i/2;
		else
			j=j/2;
	}
	printf("%d\n",i);
}


int main()
{
	int x, y;
	int i, j;
	scanf("%d%d",&x,&y);
	while (x != y)
	{
		if (x > y)
			x /= 2;
		else if (x < y)
			y /= 2;
	}
	printf("%d",x);
	return 0;
}