#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 1000005
#define uns unsigned
#define INF 0x3f3f3f3f
using namespace std;
inline ll read(){
	ll x=0;bool f=1;char s=getchar();
	while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
	while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return f?x:-x;
}
ll n,k,s,a,b,sum[MAXN<<2];
inline ll fgg(ll s){
	if(s>(n<<1)||s<2)return 0;
	if(s<=n+1)return s-1;
	else return n-(s-n)+1;
}
inline ll gee(ll s){
	ll rank=0;
	for(int i=1;i<=n&&i<s;i++)rank+=sum[s-i];
	return rank;
}
int main()
{
	n=read(),k=read();
	for(int i=1;i<=(n<<2);i++)sum[i]=sum[i-1]+fgg(i);
	s=2;
	for(int i=22;i>=0;i--)
		if(s+(1ll<<i)<=n*3&&gee(s+(1ll<<i))<k)
			s+=(1ll<<i);
	k-=gee(s),s++;
//	printf("%lld %lld %lld %lld\n",gee(3),gee(4),gee(5),gee(6));
//	printf(" %lld %lld\n",s,k);
	for(a=max(1ll,s-(n<<1));a<=n;){
		if(fgg(s-a)>=k)break;
		else k-=fgg(s-a),a++;
	}
//	printf(" %lld %lld\n",a,k);
	b=max(1ll,s-a-n)+k-1;
	printf("%lld %lld %lld\n",a,b,s-a-b);
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define For(i,a,b) for(register int i=a;i<=b;++i)
#define Down(i,a,b) for(register int i=a;i>=b;i--)
#define reg register
namespace yspm{
	inline int read(){
		int res=0,f=1; char k;
		while(!isdigit(k=getchar())) if(k=='-') f=-1;
		while(isdigit(k)) res=res*10+k-'0',k=getchar();
		return res*f;
	}
	char s[1010][1010]; 
	int n,m,fa[3000]; 
	set<int> lin,col;
	inline int min(int x,int y){return x<y?x:y;}
	inline int max(int x,int y){return x>y?x:y;}
	inline void swap(int &x,int &y){int t=x; x=y; y=t; return ;}
	inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
	inline void merge(int x,int y){
		x=find(x); y=find(y); if(x==y) return ;
		if(x>y) swap(x,y); fa[y]=x; return ;
	} 
	signed main(){
		n=read(); m=read(); For(i,1,n) scanf("%s",s[i]+1); 
		for(reg int i=1;i<=n+m;++i) fa[i]=i; fa[1]=fa[n]=fa[n+1]=fa[n+m]=1;
		For(i,1,n){
			int pre=0; For(j,1,m) if(s[i][j]=='#') merge(i,j+n),pre?merge(pre+n,j+n):void(),pre=j;
		}
		For(i,1,m){
			int pre=0; For(j,1,n) if(s[j][i]=='#') merge(j,n+i),pre?merge(pre,j):void(),pre=j;
		}
		for(reg int i=1;i<=n;++i) if(find(i)!=1) lin.insert(find(i)); 
		for(reg int i=n+1;i<=n+m;++i) if(find(i)!=1) col.insert(find(i));
		printf("%lld\n",min(lin.size(),col.size())); 
		return 0;
	}
}
signed main(){return yspm::main();}

