// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<cstdio>

#include<cstdlib>

#include<cmath>

#include<set>

#include<vector>

using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)

#define rep(i,n)   REP(i,0,n)

#define ALL(C)     (C).begin(),(C).end()



const int N = 8;

const int inf = (1<<20);

char m[N][N];



inline int getval(int c,int j,int bit){

  if      (j == -1)j=0;

  else if (j ==  c)j=c-1;

  return (bit&(1<<j)) != 0;

}



inline int checkij(int r,int c,int i,int j,int bit0,int bit1,int bit2){

  int ret=0;

  int bit=0;

  //bit0

  if (i-1 < 0)bit=bit1;

  else        bit=bit0;

  REP(k,-1,2)ret+=getval(c,j+k,bit);



  //bit1

  bit=bit1;

  REP(k,-1,2)ret+=getval(c,j+k,bit);



  //bit2

  if (i+1 == r)bit=bit1;

  else         bit=bit2;

  REP(k,-1,2)ret+=getval(c,j+k,bit);

  return ret;

}



inline bool isvalid(int r,int c,int now,int bit0,int bit1,int bit2){

  rep(j,c){

    int cnt=checkij(r,c,now-1,j,bit0,bit1,bit2);

    if ((m[now-1][j] == '#'&&cnt>=5) ||

	(m[now-1][j] == '.'&&cnt<5 ));

    else return false;

  }

  return true;

}



int dp[1<<N][1<<N][N];

int dp2[1<<N][1<<N][N];

int bitcount[1<<N];



int solvemax(int r,int c,int bit0,int bit1,int now){

  if (now == r){

    return isvalid(r,c,now,bit0,bit1,0)?bitcount[bit1]:-inf;

  }

  int &ret=dp[bit0][bit1][now-1];

  if (ret == -2*inf){

    //ret=bitcount[bit1];

    ret=-inf;

    rep(i,(1<<c)){

      if (isvalid(r,c,now,bit0,bit1,i)){

	ret=max(ret,solvemax(r,c,bit1,i,now+1)+bitcount[bit1]);

      }

    }

  }

  return ret;

}





int solvemin(int r,int c,int bit0,int bit1,int now){

  if (now == r){

    return isvalid(r,c,now,bit0,bit1,0)?bitcount[bit1]:inf;

  }

  int &ret=dp2[bit0][bit1][now-1];

  if (ret == 2*inf){

    ret=inf;

    rep(i,(1<<c)){

      if (isvalid(r,c,now,bit0,bit1,i)){

	ret=min(ret,solvemin(r,c,bit1,i,now+1)+bitcount[bit1]);

      }

    }

  }

  return ret;

}



void solve(int r,int c,int bit0,int bit1,int now){

  if (now == r){

    if (isvalid(r,c,now,bit0,bit1,0)){

      dp[ bit0][bit1][now-1]=bitcount[bit1];

      dp2[bit0][bit1][now-1]=bitcount[bit1];

    }else {

      dp[ bit0][bit1][now-1] =-inf;

      dp2[bit0][bit1][now-1]= inf;

    }

    return;

  }

  int &ret= dp[ bit0][bit1][now-1];

  int &ret2=dp2[bit0][bit1][now-1];

  if (ret == -2*inf ){

    ret=-inf;

    ret2=inf;

    rep(i,(1<<c)){

      if (isvalid(r,c,now,bit0,bit1,i)){

	solve(r,c,bit1,i,now+1);

	if (dp[bit1][i][now] != -inf){

	  ret =max(ret, dp[bit1][i][now]+bitcount[bit1]);

	}

	if (dp2[bit1][i][now] != inf){

	  ret2=min(ret2,dp2[bit1][i][now]+bitcount[bit1]);

	}

      }

    }

  }

  return;

}



/*

main(){

  rep(i,(1<<N))bitcount[i]=__builtin_popcount(i);

  int c,r,tc=1;

  while(cin>>c>>r && r){

    cout <<"Case " << tc++ << ": ";

    rep(i,r)cin>>m[i];

    rep(i,(1<<c)){

      rep(j,(1<<c)){

	rep(k,r){

	  dp[i][j][k]=-2*inf;

	  dp2[i][j][k]=2*inf;

	}

      }

    }

    //rep(i,(1<<c))rep(j,(1<<c))rep(k,r)dp2[i][j][k]=2*inf;

    int maxi=-2*inf,mini=inf;

    rep(i,(1<<c)){

      maxi=max(maxi,solvemax(r,c,0,i,1));

    }



    if (maxi < 0){

      cout <<"Impossible" << endl;

      continue;

    }//else  cout << maxi-mini << endl;

    //cout <<  mini <<" " << maxi << endl;



    //rep(i,(1<<c))rep(j,(1<<c))rep(k,r)dp[i][j][k]=2*inf;

    mini=inf;

    rep(i,(1<<c)){

      //cout << "huga " << i<<" "<< solvemin(r,c,0,i,1) << endl;

      mini=min(mini,solvemin(r,c,0,i,1));

    }

    //cout <<"true " << mini << endl;

    cout << maxi-mini << endl;

  }

  return false;

}

*/





main(){

  rep(i,(1<<N))bitcount[i]=__builtin_popcount(i);

  int c,r,tc=1;

  while(cin>>c>>r && r){

    cout <<"Case " << tc++ << ": ";

    rep(i,r)cin>>m[i];

    rep(i,(1<<c)){

      rep(j,(1<<c)){

	rep(k,r){

	  dp[i][j][k]=-2*inf;

	  dp2[i][j][k]=2*inf;

	}

      }

    }

    int maxi=-2*inf,mini=inf;

    rep(i,(1<<c)){

      solve(r,c,0,i,1);

      if (dp[0][i][0] >= 0)maxi=max(maxi,dp[0][i][0]);

      //cout << "hoge " << i<<" " << dp2[0][i][0] << endl;

      if (dp2[0][i][0] != inf)mini=min(mini,dp2[0][i][0]);

    }



    if (maxi < 0){

      cout <<"Impossible" << endl;

      continue;

    }else  cout << maxi-mini << endl;



    /*

    mini=inf;

    rep(i,(1<<c)){

      mini=min(mini,solvemin(r,c,0,i,1));

    }

    cout << maxi-mini << endl;

    */

  }

  return false;

}







/*

void test(){

  int bit0=17,bit1=14,bit2=24;

  int r=3,c=5;

  rep(j,c)cout << checkij(r,c,0,j,0,bit0,bit1)<<" ";cout << endl;

  rep(j,c)cout << checkij(r,c,1,j,bit0,bit1,bit2)<<" ";cout << endl;

  rep(j,c)cout << checkij(r,c,2,j,bit1,bit2,0)<<" ";cout << endl;

}



void output(int c,int bit){

  rep(j,c){

    if ((1<<j)&bit) cout <<"#";

    else cout << ".";

  }

  cout << endl;

}



*/

// Faster C++ solution for the same problem (measured speedup: 1.1701422137237454x):
#include<iostream>

#include<algorithm>

#include<cstdio>

#include<cstdlib>

#include<cmath>

#include<set>

#include<vector>

using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)

#define rep(i,n)   REP(i,0,n)

#define ALL(C)     (C).begin(),(C).end()



const int N = 8;

const int inf = (1<<20);

char m[N][N];



inline int getval(int c,int j,int bit){

  if      (j == -1)j=0;

  else if (j ==  c)j=c-1;

  return (bit&(1<<j)) != 0;

}



inline int checkij(int r,int c,int i,int j,int bit0,int bit1,int bit2){

  int ret=0;

  int bit=0;

  //bit0

  if (i-1 < 0)bit=bit1;

  else        bit=bit0;

  REP(k,-1,2)ret+=getval(c,j+k,bit);



  //bit1

  bit=bit1;

  REP(k,-1,2)ret+=getval(c,j+k,bit);



  //bit2

  if (i+1 == r)bit=bit1;

  else         bit=bit2;

  REP(k,-1,2)ret+=getval(c,j+k,bit);

  return ret;

}



inline bool isvalid(int r,int c,int now,int bit0,int bit1,int bit2){

  rep(j,c){

    int cnt=checkij(r,c,now-1,j,bit0,bit1,bit2);

    if ((m[now-1][j] == '#'&&cnt>=5) ||

	(m[now-1][j] == '.'&&cnt<5 ));

    else return false;

  }

  return true;

}



int dp[1<<N][1<<N][N];

int dp2[1<<N][1<<N][N];

int bitcount[1<<N];



void solve(int r,int c,int bit0,int bit1,int now){

  if (now == r){

    if (isvalid(r,c,now,bit0,bit1,0)){

      dp[ bit0][bit1][now-1]=bitcount[bit1];

      dp2[bit0][bit1][now-1]=bitcount[bit1];

    }else {

      dp[ bit0][bit1][now-1] =-inf;

      dp2[bit0][bit1][now-1]= inf;

    }

    return;

  }

  int &ret= dp[ bit0][bit1][now-1];

  int &ret2=dp2[bit0][bit1][now-1];

  if (ret == -2*inf ){

    ret=-inf;

    ret2=inf;

    rep(i,(1<<c)){

      if (isvalid(r,c,now,bit0,bit1,i)){

	solve(r,c,bit1,i,now+1);

	if (dp[bit1][i][now] != -inf){

	  ret =max(ret, dp[bit1][i][now]+bitcount[bit1]);

	  ret2=min(ret2,dp2[bit1][i][now]+bitcount[bit1]);

	}

      }

    }

  }

  return;

}



main(){

  rep(i,(1<<N))bitcount[i]=__builtin_popcount(i);

  int c,r,tc=1;

  while(cin>>c>>r && r){

    cout <<"Case " << tc++ << ": ";

    rep(i,r)cin>>m[i];

    rep(i,(1<<c)){

      rep(j,(1<<c)){

	rep(k,r){

	  dp[i][j][k]=-2*inf;

	  //dp2[i][j][k]=2*inf;

	}

      }

    }

    int maxi=-2*inf,mini=inf;

    rep(i,(1<<c)){

      solve(r,c,0,i,1);

      if (dp[0][i][0] >= 0){

	maxi=max(maxi,dp[0][i][0]);

	mini=min(mini,dp2[0][i][0]);

      }

    }



    if (maxi < 0){

      cout <<"Impossible" << endl;

      continue;

    }else  cout << maxi-mini << endl;

  }

  return false;

}







/*

void test(){

  int bit0=17,bit1=14,bit2=24;

  int r=3,c=5;

  rep(j,c)cout << checkij(r,c,0,j,0,bit0,bit1)<<" ";cout << endl;

  rep(j,c)cout << checkij(r,c,1,j,bit0,bit1,bit2)<<" ";cout << endl;

  rep(j,c)cout << checkij(r,c,2,j,bit1,bit2,0)<<" ";cout << endl;

}



void output(int c,int bit){

  rep(j,c){

    if ((1<<j)&bit) cout <<"#";

    else cout << ".";

  }

  cout << endl;

}



*/