#include <iostream>
#include <fstream>
using namespace std;

int n,best;
int sx[6],sy[6];
char item[6][6][6];
char boxes[6][6][6];
bool done[6];
bool STOP;

void rec(int cur,int i)
{
	//vars
	int a,b,y,x,Y,X;
	char tmp[6][6];
	//done?
		for (a=0; a<n; a++)
			if (!done[a])
				goto cont;
		if (cur<best)
		{
			best=cur;
			STOP=true;
		}
	//find an item to put in this box
cont:
		if (STOP)
			return;
		for (a=i; a<n; a++)
			if (!done[a])
			for (y=0; y+sy[a]-1<5; y++)
				for (x=0; x+sx[a]-1<5; x++)
				{
					memcpy(tmp,boxes[cur],sizeof(tmp));
						for (Y=y; Y<y+sy[a]; Y++)
							for (X=x; X<x+sx[a]; X++)
								if ((boxes[cur][Y][X]=='#') && (item[a][Y-y][X-x]=='#'))
									goto skip;
								else
								if (item[a][Y-y][X-x]=='#')
									boxes[cur][Y][X]='#';
					done[a]=true;
					rec(cur,a+1);
					done[a]=false;
						if (STOP)
							return;
skip:
					memcpy(boxes[cur],tmp,sizeof(tmp));
				}
	//no such item - make new box!
		for (a=0; a<6; a++)
			for (b=0; b<6; b++)
				boxes[cur+1][a][b]='.';
	rec(cur+1,0);
}

int main()
{
	//vars
	ifstream cin ("DATA5.txt");
	//ofstream cout ("OUT5.txt");
	int a,b,c;
	//testcase loop
	int t=5;
		while (t--)
		{
			//input
			cin >> n;
			cin.getline(item[0][0],6,'\n');
				for (a=0; a<n; a++)
				{
					//get item
					sy[a]=0;
again:
					cin.getline(item[a][sy[a]],6,'\n');
						if (strlen(item[a][sy[a]])==0)
							goto out;
					sy[a]++;
					goto again;
out:
					sx[a]=strlen(item[a][0]);
					//remove extra lines
						while (true)
						{
								for (b=0; b<sy[a]; b++)
									if (item[a][b][0]=='#')
										goto out1;
							sx[a]--;
								for (b=0; b<sx[a]; b++)
									for (c=0; c<sy[a]; c++)
										item[a][c][b]=item[a][c][b+1];
						}
out1:
						while (true)
						{
								for (b=0; b<sy[a]; b++)
									if (item[a][b][sx[a]-1]=='#')
										goto out2;
							sx[a]--;
						}
out2:
						while (true)
						{
								for (b=0; b<sx[a]; b++)
									if (item[a][0][b]=='#')
										goto out3;
							sx[a]--;
								for (b=0; b<sy[a]; b++)
									for (c=0; c<sx[a]; c++)
										item[a][b][c]=item[a][b+1][c];
						}
out3:
						while (true)
						{
								for (b=0; b<sx[a]; b++)
									if (item[a][sy[a]-1][b]=='#')
										goto out4;
							sy[a]--;
						}
out4:
					a=a;
				}
			//recursive-non-dynamic
			best=99;
			STOP=false;
				for (a=0; a<6; a++)
					for (b=0; b<6; b++)
						boxes[0][a][b]='.';
			memset(done,false,sizeof(done));
			rec(0,0);
			//output
			cout << best << endl;
		}
	return(0);
}
