#include<bits/stdc++.h>
#define r(i,n)for(int i=0;i<n;i++)
using namespace std;
int n,m,a[23],pp=0;
int main(){
  while(cin>>n>>m,n){
    cout<<"Case "<<++pp<<": ";
    int cnt=0;
    memset(a,0,sizeof(a));
    a[0]=n;
    while(1){
      cnt++;
      int p=0;
      for(int i=20;i>=0;i--){
	p+=a[i]/2;
	a[i+1]+=a[i]/2;
	a[i]=a[i]%2;
      }
      a[0]+=p;
      if(a[m]){
	cout<<cnt<<endl;
	break;
      }
    }
  }
}