#include<stdio.h>
#include<algorithm>
using namespace std;
int c[12][12];
int C[12];
int h[12][12][200];
int w[12][12][200];
int n[12][12][200];
int sz[12][12];
int P[12][12];
int H,W;
int valid(int a,int b,int t){
	if(a<0||b<0||a+t>H||b+t>W)return 0;
	for(int i=0;i<t;i++)for(int j=0;j<t;j++)if(!c[a+i][b+j])return 0;
	return 1;
}
int lim;
int dfs(int a,int b,int v){
	if(a==H)return 1;
	if(b==W)return dfs(a+1,0,v);
	if(((C[a]>>(b*2))&3)!=1)return dfs(a,b+1,v);
	if(v==lim)return 0;
	int last[12];
	for(int i=0;i<H;i++)last[i]=C[i];
	for(int i=0;i<sz[a][b];i++){
		for(int j=0;j<n[a][b][i];j++)C[h[a][b][i]+j]|=P[w[a][b][i]][w[a][b][i]+n[a][b][i]-1];
		if(dfs(a,b+1,v+1))return 1;
		for(int j=0;j<n[a][b][i];j++)C[h[a][b][i]+j]=last[h[a][b][i]+j];
	}
	return 0;
}
int main(){
	int a,b;
	while(scanf("%d%d",&b,&a),a){
		
		H=a;W=b;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&c[i][j]);
		for(int i=0;i<a;i++)C[i]=0;
		
		for(int i=0;i<b;i++)for(int j=i;j<b;j++){
			P[i][j]=0;
			for(int k=i;k<=j;k++){
				P[i][j]+=1<<(k*2+1);
			}
	//		printf("%d %d: %d\n",i,j,P[i][j]);
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)sz[i][j]=0;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			for(int k=1;k<=min(a,b);k++){
				if(valid(i,j,k)&&!valid(i-1,j-1,k+1)&&!valid(i-1,j,k+1)&&!valid(i,j-1,k+1)&&!valid(i,j,k+1)){
					for(int l=0;l<k;l++)for(int m=0;m<k;m++){
						h[i+l][j+m][sz[i+l][j+m]]=i;
						w[i+l][j+m][sz[i+l][j+m]]=j;
						n[i+l][j+m][sz[i+l][j+m]]=k;
						sz[i+l][j+m]++;
					//	printf("%d %d %d %d %d\n",i,j,k,i+l,j+m);
					}
				}
			}
		}
		//for(int j=0;j<b;j++)for(int k=0;k<sz[i][j];k++);
		//	printf("%d %d: %d %d %d\n",i,j,h[i][j][k],w[i][j][k],n[i][j][k]);
		int ad=0;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			int M=0;
			for(int k=0;k<sz[i][j];k++)M=max(M,n[i][j][k]);
			if(M==1){
				ad++;
				c[i][j]=0;
			}
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)C[i]+=(c[i][j]<<(j*2));
		for(int i=0;;i++){
			lim=i;
			if(dfs(0,0,0)){
				printf("%d\n",ad+i);
				break;
			}
		}
	}
}
### Prompt

Please formulate a cpp solution to the following problem:

Mr. Frugal bought a new house. He feels deeply in love with his new house because it has a comfortable living room in which he can put himself completely at ease. He thinks his new house is a really good buy.

But, to his disappointment, the floor of its living room has some scratches on it.

The floor has a rectangle shape, covered with square panels. He wants to replace all the scratched panels with flawless panels, but he cannot afford to do so. Then, he decides to cover all the scratched panels with carpets.

The features of the carpets he can use are as follows.

1. Carpets are square-shaped.
2. Carpets may overlap each other.
3. Carpets cannot be folded.
4. Different sizes of carpets are available. Lengths of sides of carpets are multiples of that of the panels.


The carpets must cover all the scratched panels, but must not cover any of the flawless ones.

For example, if the scratched panels are as shown in Figure 1, at least 6 carpets are needed.

<image>
---
Figure 1: Example Covering

As carpets cost the same irrespective of their sizes, Mr. Frugal would like to use as few number of carpets as possible.

Your job is to write a program which tells the minimum number of the carpets to cover all the scratched panels.



Input

The input consists of multiple data sets. As in the following, the end of the input is indicated by a line containing two zeros.

> DataSet1
>  DataSet2
>  ...
>  DataSetn
>  `0` `0`

Each data set (DataSeti) represents the state of a floor. The format of a data set is as follows.

> W H
>  P11 P12 P13 ... P1W
>  P21 P22 P23 ... P2W
>  ...
>  PH1 PH2 PH3 ... PHW
>

The positive integers W and H are the numbers of panels on the living room in the x- and y- direction, respectively. The values of W and H are no more than 10. The integer Pyx represents the state of the panel. The value of Pyx means,

> `0`: flawless panel (must not be covered),
>  `1`: scratched panel (must be covered).

Output

For each data set, your program should output a line containing one integer which represents the minimum number of the carpets to cover all of the scratched panels.

Example

Input

4 3
0 1 1 1
1 1 1 1
1 1 1 1
8 5
0 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 0 1 1 1 1
0 1 1 1 0 1 1 1
8 8
0 1 1 0 0 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 0 0 1 1 0
10 10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
0 0


Output

2
6
14
29

### Response

```cpp
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[12][12];
int C[12];
int h[12][12][200];
int w[12][12][200];
int n[12][12][200];
int sz[12][12];
int P[12][12];
int H,W;
int valid(int a,int b,int t){
	if(a<0||b<0||a+t>H||b+t>W)return 0;
	for(int i=0;i<t;i++)for(int j=0;j<t;j++)if(!c[a+i][b+j])return 0;
	return 1;
}
int lim;
int dfs(int a,int b,int v){
	if(a==H)return 1;
	if(b==W)return dfs(a+1,0,v);
	if(((C[a]>>(b*2))&3)!=1)return dfs(a,b+1,v);
	if(v==lim)return 0;
	int last[12];
	for(int i=0;i<H;i++)last[i]=C[i];
	for(int i=0;i<sz[a][b];i++){
		for(int j=0;j<n[a][b][i];j++)C[h[a][b][i]+j]|=P[w[a][b][i]][w[a][b][i]+n[a][b][i]-1];
		if(dfs(a,b+1,v+1))return 1;
		for(int j=0;j<n[a][b][i];j++)C[h[a][b][i]+j]=last[h[a][b][i]+j];
	}
	return 0;
}
int main(){
	int a,b;
	while(scanf("%d%d",&b,&a),a){
		
		H=a;W=b;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&c[i][j]);
		for(int i=0;i<a;i++)C[i]=0;
		
		for(int i=0;i<b;i++)for(int j=i;j<b;j++){
			P[i][j]=0;
			for(int k=i;k<=j;k++){
				P[i][j]+=1<<(k*2+1);
			}
	//		printf("%d %d: %d\n",i,j,P[i][j]);
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)sz[i][j]=0;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			for(int k=1;k<=min(a,b);k++){
				if(valid(i,j,k)&&!valid(i-1,j-1,k+1)&&!valid(i-1,j,k+1)&&!valid(i,j-1,k+1)&&!valid(i,j,k+1)){
					for(int l=0;l<k;l++)for(int m=0;m<k;m++){
						h[i+l][j+m][sz[i+l][j+m]]=i;
						w[i+l][j+m][sz[i+l][j+m]]=j;
						n[i+l][j+m][sz[i+l][j+m]]=k;
						sz[i+l][j+m]++;
					//	printf("%d %d %d %d %d\n",i,j,k,i+l,j+m);
					}
				}
			}
		}
		//for(int j=0;j<b;j++)for(int k=0;k<sz[i][j];k++);
		//	printf("%d %d: %d %d %d\n",i,j,h[i][j][k],w[i][j][k],n[i][j][k]);
		int ad=0;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			int M=0;
			for(int k=0;k<sz[i][j];k++)M=max(M,n[i][j][k]);
			if(M==1){
				ad++;
				c[i][j]=0;
			}
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)C[i]+=(c[i][j]<<(j*2));
		for(int i=0;;i++){
			lim=i;
			if(dfs(0,0,0)){
				printf("%d\n",ad+i);
				break;
			}
		}
	}
}
```