/*
 *  eat_code
 */
#include <bits/stdc++.h>
using namespace std;

//#define DEBUG
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define endl '\n'
#define LSOne(S) (S & (-S))
#define what_is(x) cout << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const ll INF = numeric_limits<ll>::max();
const ll MOD = 1E9 + 7;
const double PI = 2 * acos(0);
ll MAXN = 1e7;
int main() {
	//boost;
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	boost;
	int n;
	ll x, y;
	cin >> n >> x >> y;
	ll cnt = 0;
	vll v;
	for(int i = 0; i < (n - 1); i++) {
	    v.pb(1);
	    cnt += 1;
	}
	v.pb((y - cnt));
	cnt += ((y - cnt)*(y - cnt));
	if(cnt >= x){
		for(int j = 0; j < n; j++) {
			cout << v[j] << "\n";
		}
	}else{
		cout << "-1" << "\n";
	}

	return 0;
}
/*
 *  Train Insane or Remain the same
 */


#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cout << #x << " = " << x << endl
#define F first
#define S second
#define LSOne(S) (S & (-S))
#define endl '\n'
#define mp make_pair
#define pb push_back
typedef vector<int> vi;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef pair<double, int> di;
typedef vector<ll> vll;
const double PI = 2 * acos(0);
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
ll INF = 123456789999;
int MAXN = 1e6;
vll empty;
int main() {
	boost;
	if(fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	int n;cin >> n;
	ll x, y, a = -1;
	cin >> x >> y;
	for (int i = 1; i <= MAXN; ++i) {
		double x1 = sqrt(x / (double) n);
		double y1 = y / (double) n;
		if((double) i >= x1 && (double) i <= y1) {
			a = i;
			break;
		}
	}
	if(a == -1)
		return 0 * puts("-1");
	for (int i = 0; i < n; ++i) {
		cout << a << endl;
	}

	return 0;
}


/*
 *  eat_code
 */
#include <bits/stdc++.h>
using namespace std;

//#define DEBUG
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define endl '\n'
#define LSOne(S) (S & (-S))
#define what_is(x) cout << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const ll INF = numeric_limits<ll>::max();
const ll MOD = 1E9 + 7;
const double PI = 2 * acos(0);
ll MAXN = 1e7;
int main() {
	//boost;
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	boost;
	int n;
	ll x, y;
	cin >> n >> x >> y;
	ll cnt = 0;
	vll v;
	for(int i = 0; i < (n - 1); i++) {
	    v.pb(1);
	    cnt += 1;
	}
	v.pb((y - cnt));
	bool f = true;
	if((y - cnt) < 0)
		f  = false;
	cnt += ((y - cnt)*(y - cnt));
	if(cnt >= x && f){
		for(int j = 0; j < n; j++) {
			cout << v[j] << "\n";
		}
	}else{
		cout << "-1" << "\n";
	}

	return 0;
}
/*
 *  Train Insane or Remain the same
 */


#include <iostream>
#include <cstdio>
#include <climits>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <set>
#include <stack>
#include <list>
#include <limits>
#include <string>
#define LL long long
#define L long
#define I int
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define FORE(i,n) for(int i=1;i<=n;i++)
#define max_size_segTree(n) 2*(int)pow(2, (int)(ceil(log2(n)))) - 1
#define mp make_pair
#define pb push_back
#define MAX 10000001
#define INF 1e18+1
using namespace std;

int main()
{
    LL n;
    LL x,y;
    cin>>n>>x>>y;
    LL ans = (LL)y-n+1LL;
    if(ans <= 0){
        cout<<"-1";
        return 0;
    }
    ans *= ans;
    ans += n-1;
    if(ans < x){
        cout<<-1<<endl;
    }else {
        LL k = (LL)y-n+1LL;
        cout<<k<<endl;
        FOR(i,0,n-1)
            cout<<1<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <climits>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <set>
#include <stack>
#include <list>
#include <limits>
#include <string>
#define LL long long
#define L long
#define I int
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define FORE(i,n) for(int i=1;i<=n;i++)
#define max_size_segTree(n) 2*(int)pow(2, (int)(ceil(log2(n)))) - 1
#define mp make_pair
#define pb push_back
#define MAX 10000001
#define INF 1e18+1
using namespace std;

int main()
{
    LL n;
    LL x,y;
    cin>>n>>x>>y;
    LL ans = (LL)y-n+1LL;
    if(ans < 0){
        cout<<"-1";
        return 0;
    }
    ans *= ans;
    ans += n-1;
    if(ans < x){
        cout<<-1<<endl;
    }else {
        LL k = (LL)y-n+1LL;
        cout<<k<<endl;
        FOR(i,0,n-1)
            cout<<1<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <climits>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <set>
#include <stack>
#include <list>
#include <limits>
#include <string>
#define LL long long
#define L long
#define I int
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define FORE(i,n) for(int i=1;i<=n;i++)
#define max_size_segTree(n) 2*(int)pow(2, (int)(ceil(log2(n)))) - 1
#define mp make_pair
#define pb push_back
#define MAX 10000001
#define INF 1e18+1
using namespace std;

int main()
{
    LL n;
    LL x,y;
    cin>>n>>x>>y;
    LL ans = (LL)y-n+1LL;
    ans *= ans;
    ans += n-1;
    if(ans < x){
        cout<<-1<<endl;
    }else {
        LL k = (LL)y-n+1LL;
        cout<<k<<endl;
        FOR(i,0,n-1)
            cout<<1<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctime>

using namespace std;

string s;
long long a[1000],b[1000],n,m,ans,mn,x,y;
int main()
{
  cin >> n >> x >> y;
  ans=(y-n+1)*(y-n+1)+n-1;
  if (ans<x) cout <<"-1";
  else for (long i=1;i<n;i++)
    cout << "1" << endl;
  cout << y-n+1;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctime>

using namespace std;

string s;
long long a[1000],b[1000],n,m,ans,mn,x,y;
int main()
{
  cin >> n >> x >> y;
  ans=(y-n+1)*(y-n+1)+n-1;
  if (ans<x) cout <<"-1";
  else {for (long i=1;i<n;i++)
    cout << "1" << endl;
  cout << y-n+1;}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctime>

using namespace std;

string s;
long long a[1000],b[1000],n,m,ans,mn,x,y;
int main()
{
  cin >> n >> x >> y;
  ans=(y-n+1)*(y-n+1)+n-1;
  if (ans<x || y-n+1<=0) cout <<"-1";
  else {for (long i=1;i<n;i++)
    cout << "1" << endl;
  cout << y-n+1;}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctime>

using namespace std;

string s;
long long a[1000],b[1000],n,m,ans,mn,x,y;
int main()
{
  cin >> n >> x >> y;
  ans=(y-n+1)*(y-n+1)+n-1;
  if (ans<x || y-n+1<0) cout <<"-1";
  else {for (long i=1;i<n;i++)
    cout << "1" << endl;
  cout << y-n+1;}
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	long long h=-1;
	for(int i=1;i<=x;i++){
		if(i*i+(n-1)>=x){
			h=i;
			break;
		}
	}
	if(h+n-1>y){
		cout<<"-1";
		return 0;
	}
	for(int i=1;i<n;i++){
		cout<<"1 ";
	}
	cout<<h;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	for(long long i=1;i<=y;i++){
		if( i*i+(n-1)>=x && i+(n-1)<=y){
			for(long long j=1;j<n;j++){
				cout<<"1 ";
			}
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	long long h;
	for(long long i=x;;i++){
		int y1=sqrt(i);
		double y2=sqrt(i);
		if(y1==y2){
			h=y1;
			break;
		}
	}
	if(n-1+h>y){
		cout<<"-1";
		return 0;
	}
	for(int i=1;i<n;i++){
		cout<<"1 ";
	}
	cout<<h;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=y;i++){
		if(i*i+(n-1)>=x&&i+(n-1)<=y){
			for(int j=1;j<n;j++){
				cout<<"1 ";
			}
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=y;i++){
		if(i*i+(n-1)>=x&&i+(n-1)<=y){
			for(int j=0;j<n;j++){
				cout<<"1 ";
			}
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	long long h;
	x-=(n-1);
	for(long long i=x;;i++){
		long long y1=sqrt(i);
		double y2=sqrt(i);
		if(y1==y2){
			h=y1;
			break;
		}
	}
	if(n-1+h>y){
		cout<<"-1";
		return 0;
	}
	for(int i=1;i<n;i++){
		cout<<"1 ";
	}
	cout<<h;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	long long h=-1;
	for(int i=1;i<=x;i++){
		if(i*i+(n-1)>=x&&i+n-1<=y){
			h=i;
			break;
		}
	}
	if(h==-1){
		cout<<"-1";
		return 0;
	}
	for(int i=1;i<n;i++){
		cout<<"1 ";
	}
	cout<<h;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
	long long n,x,y;
	cin>>n>>x>>y;
	long long h;
	for(int i=1;i<=x;i++){
		if(i*i+(n-1)>=x){
			h=i;
			break;
		}
	}
	for(int i=1;i<n;i++){
		cout<<"1 ";
	}
	cout<<h;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5,MOD=1e9+7;

int main()
{
    int n,s;
    ll m;
    scanf("%d %lld %d",&n,&m,&s);
    ll x=(s-(n-1));
    if (!x || x*x+n-1<m) return cout<<"-1",0;
    else {
        printf("%lld\n",x);
        for (int i=0;i<n-1;i++) printf("1\n");
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5,MOD=1e9+7;

int main()
{
    int n,s;
    ll m;
    scanf("%d %lld %d",&n,&m,&s);
    ll x=(s-(n-1));
    if (x<=0 || x*x+n-1<m) return cout<<"-1",0;
    else {
        printf("%lld\n",x);
        for (int i=0;i<n-1;i++) printf("1\n");
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5,MOD=1e9+7;

int main()
{
    int n,s;
    ll m;
    scanf("%d %lld %d",&n,&m,&s);
    ll x=(s-(n-1));
    if (x*x+n-1<m) return cout<<"-1",0;
    else {
        printf("%lld\n",x);
        for (int i=0;i<n-1;i++) printf("1\n");
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<functional>
#include<cstring>
#include<bitset>
#include<cmath>
#include<bitset>
#include<sstream>
#include<list>
using namespace std;

static long long n, x, y;

int main()
{
	while (scanf("%I64d%I64d%I64d", &n, &x, &y) != EOF)
	{
		if (y - n + 1 < 0)
		{
			printf("-1\n");
			continue;
		}
		long long ans = pow(y - n + 1, 2);
		//printf("%I64d\n", ans);
		for (int i = 1; i < n; i++)
		{
			ans += 1;
		}
		if (ans < x)
		{
			printf("-1\n");
		}
		else
		{
			printf("%I64d\n", y - n + 1);
			for (int i = 1; i < n; i++) printf("1\n");
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<functional>
#include<cstring>
#include<bitset>
#include<cmath>
#include<bitset>
#include<sstream>
#include<list>
using namespace std;

static long long n, x, y;

int main()
{
	while (scanf("%I64d%I64d%I64d", &n, &x, &y) != EOF)
	{
		if (y < n)
		{
			printf("-1\n");
			continue;
		}
		long long ans = pow(y - n + 1, 2);
		//printf("%I64d\n", ans);
		for (int i = 1; i < n; i++)
		{
			ans += 1;
		}
		if (ans < x)
		{
			printf("-1\n");
		}
		else
		{
			printf("%I64d\n", y - n + 1);
			for (int i = 1; i < n; i++) printf("1\n");
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<functional>
#include<cstring>
#include<bitset>
#include<cmath>
#include<bitset>
#include<sstream>
#include<list>
using namespace std;

static long long n, x, y;

int main()
{
	while (scanf("%I64d%I64d%I64d", &n, &x, &y) != EOF)
	{
		long long ans = pow(y - n + 1, 2);
		//printf("%I64d\n", ans);
		for (int i = 1; i < n; i++)
		{
			ans += 1;
		}
		if (ans < x)
		{
			printf("-1\n");
		}
		else
		{
			printf("%I64d\n", y - n + 1);
			for (int i = 1; i < n; i++) printf("1\n");
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<functional>
#include<cstring>
#include<bitset>
#include<cmath>
#include<bitset>
#include<sstream>
#include<list>
using namespace std;

static long long n, x, y;

int main()
{
	while (scanf("%I64d%I64d%I64d", &n, &x, &y) != EOF)
	{
		if (y - n + 1 <= 0)
		{
			printf("-1\n");
			continue;
		}
		long long ans = pow(y - n + 1, 2);
		//printf("%I64d\n", ans);
		for (int i = 1; i < n; i++)
		{
			ans += 1;
		}
		if (ans < x)
		{
			printf("-1\n");
		}
		else
		{
			printf("%I64d\n", y - n + 1);
			for (int i = 1; i < n; i++) printf("1\n");
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int INF  = 0x3f3f3f3f;
const int maxn = 100008;
const int Mod  = 1e9 + 7;

#define ll       long long
#define mem(x,y) memset(x,y,sizeof(x))
#define IO       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int main() {
    long long n, x, y;
    cin >> n >> x >> y;
    if (y < n) {
        cout << -1 << endl;
        return 0;
    }
    if ( (y - n + 1) * (y - n + 1) + (n - 1) >= x ) {
        cout << y - n + 1 << endl;
        for (int i = 1; i <= n - 1; i++)
            cout << 1 << endl;
    } else {
        cout << -1 << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

const int INF  = 0x3f3f3f3f;
const int maxn = 100008;
const int Mod  = 1e9 + 7;

#define ll       long long
#define mem(x,y) memset(x,y,sizeof(x))
#define IO       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int main() {
    long long n, x, y;
    cin >> n >> x >> y;
    if ( (y - n + 1) * (y - n + 1) + (n - 1) >= x ) {
        cout << y - n + 1 << endl;
        for (int i = 1; i <= n - 1; i++)
            cout << 1 << endl;
    } else {
        cout << -1 << endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void solve();

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

void solve() {
	ll n, x, y;
	cin >> n >> x >> y;

	ll k = pow (y - (n-1), 2);
	if (k>=x) {
		cout << y - (n-1) << " ";
		for (ll i = 0; i < (n-1); i++) {
			cout << "1 ";
		}
	} else {
		cout << "-1";
	}
}


#include<bits/stdc++.h>

using namespace std;

void solve();

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

void solve() {
	int n, x, y;
	int a[100000];
	cin >> n >> x >> y;
	int s = 0;
	int t=0;
	/*for (int i=0; i<n; i++) {
		a[i] = 1;
		//s += a[i];
		//t += a[i]*a[i];
	}*/
	int k = pow (y - (n-1), 2);
	if (k>x) {
		cout << y - (n-1) << " ";
		for (int i = 0; i < (n-1); i++) {
			cout << "1 ";
		}
	} else {
		cout << "-1";
	}
	// >= x;
	/*while (t<x) {
		for (int i=0; i<n; i++) {
			t = t - a[i]*a[i];
			s = s - a[i];
			a[i]++;
			s = s + a[i];
			t = t + a[i]*a[i];
			if (s > y)
		}
	}*/
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void solve();

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

void solve() {
	ll n, x, y;
	cin >> n >> x >> y;

	ll k = pow (y - (n-1), 2);

	if (k+(n-1)>=x) {
		cout << y - (n-1) << " ";
		for (ll i = 0; i < (n-1); i++) {
			cout << "1 ";
		}
	} else {
		cout << "-1";
	}
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void solve();

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

void solve() {
	ll n, x, y;
	cin >> n >> x >> y;

	ll k = pow (y - (n-1), 2);

	if (k+(n-1)>=x and (n <= y)) {
		cout << y - (n-1) << " ";
		for (ll i = 0; i < (n-1); i++) {
			cout << "1 ";
		}
	} else {
		cout << "-1";
	}
}


#include <iostream>
#include <vector>

using std::vector;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long n,x,y;
    cin >> n >> x >> y;
    if (n > y)
    {
        cout << "-1" << endl;
    }
    else
    {
        long long sum = (y-n+1)*(y-n+1) + (n-1);
        if (sum < x)
        {
            cout << "-1"<< endl;
        }
        else
        {
            cout << (y-n+1) << endl;
            for (int i=1;i < n; i++)
                cout <<"1"<<endl;
        }

    }

}


#include <bits/stdc++.h>

using namespace std;
//#define int long long
const int maxN = 100*1000 + 5;
const int mod = 1000*1000*1000 + 7;
char a[53][53];
int mark[53][53];
int dp[53][53];
int h[53][53];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int n, m;
int Xr, Yr;

void dfs(int x, int y)
{
//    cout << x << ' ' << y << endl;
    mark[x][y] = 1; dp[x][y] = h[x][y];
    int cnt = 0;
    for(int i = 0; i < 4; i ++)
    {
	  int v = x + dx[i], u = y + dy[i];

	  if(v < 0 || u < 0 || u == m || v == n) continue;
	  if(a[v][u] != '#') continue;

	  if(!mark[v][u])
	  {
		h[v][u] = h[x][y] + 1;
		dfs(v, u);
		if(dp[v][u] >= h[x][y] && (Xr != x || Yr != y)) {cout << 1 << endl; exit(0); }
		dp[x][y] = min(dp[v][u], dp[x][y]);
		if(Xr == x && Yr == y) cnt ++;
	  }
	  else
		dp[x][y] = min(dp[x][y], h[v][u]);
    }

    if(Xr == x && Yr == y && cnt > 1)
    {
	  cout << 1 << endl; exit(0);
    }
}
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    int te = 0;
    for(int i = 0; i < n; i ++)
	  for(int j = 0; j < m; j ++)
		cin >> a[i][j], te += (a[i][j] == '#' ? 1 : 0);
    if(te == 1) { cout << -1 << endl; return 0; }
    for(int i = 0; i < n; i ++)
	  for(int j = 0; j < m; j ++)
		if(a[i][j] == '#')
		{
		    Xr = i; Yr = j;
		    dfs(i, j);
		    cout << 2 << endl;
		    return 0;
		}
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

void dfs(vs& grid,int i,int j)
{
	int h=grid.size(),w=grid[0].size();
	if(i<0 || h<=i || j<0 || w<=j || grid[i][j]=='.')
		return;
	grid[i][j]='.';
	rep(k,4){
		int ni=i+"\xff\x1\0\0"[k],nj=j+"\0\0\xff\x1"[k];
		dfs(grid,ni,nj);
	}
}

int connected(vs grid)
{
	int res=0;
	rep(i,grid.size()) rep(j,grid[i].size())
		if(grid[i][j]=='#'){
			dfs(grid,i,j);
			res++;
		}
	return res;
}

int solve(vs grid)
{
	int h=grid.size(),w=grid[0].size();
	{
		int sharp=0;
		rep(i,h)
			sharp+=count(all(grid[i]),'#');
		if(sharp<=2){
			return -1;
		}
	}
	rep(i,h) rep(j,w) if(grid[i][j]=='#'){
		grid[i][j]='.';
		if(connected(grid)>1)
			return 1;
		grid[i][j]='#';
	}
	return 2;
}

int main()
{
	for(int h,w;cin>>h>>w;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		cout<<solve(grid)<<endl;
	}

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int h,w;cin>>h>>w;){
		vs grid(h);
		rep(i,h) cin>>grid[i];

		{
			int sharp=0;
			rep(i,h)
				sharp+=count(all(grid[i]),'#');
			if(sharp<=2){
				cout<<-1<<endl;
				continue;
			}
		}

		int res=INT_MAX;
		rep(i,h) rep(j,w) if(grid[i][j]=='#'){
			int cnt=0;
			rep(k,4){
				int ni=i+"\xff\x1\0\0"[k],nj=j+"\0\0\xff\x1"[k];
				if(0<=ni && ni<h && 0<=nj && nj<w && grid[ni][nj]=='#')
					cnt++;
			}
			res=min(res,cnt);
		}
		cout<<res<<endl;
	}

	return 0;
}


		//			- -- --- ---- -----be name khoda----- ---- --- -- -			\\

#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int a[N][N], n, m, is;
int x[] = {0, 0, 1, -1};
int y[] = {1, -1, 0, 0};
bool mark[N][N];

void dfs(int i, int j)
{
	mark[i][j] = 1;
	for(int mv = 0; mv < 4; mv++)
	{
		int ii = i + x[mv];
		int jj = j + y[mv];
		if(min(ii, jj) >= 1 && ii <= n && jj <= m)
			if(!mark[ii][jj] && a[ii][jj])
				dfs(ii, jj);
	}
}

bool check(int i, int j)
{
	if(!a[i][j])
		return 0;
	for(int k = 0; k <= n; k++)
		fill(mark[k], mark[k] + m + 1, 0);
	mark[i][j] = 1;
	bool done = 0;
	for(int k = 0; k < 4; k++)
	{
		int ii = i + x[k];
		int jj = j + y[k];
		if(min(ii, jj) >= 1 && ii <= n && jj <= m)
			if(a[ii][jj])
				if(!mark[ii][jj])
					if(!done)
					{
						dfs(ii, jj);
						done = 1;
					}
					else
						return 1;
	}
	return 0;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			char c;
			cin >> c;
			a[i][j] = (c == '#');
			is += a[i][j];
		}
	if(is <= 2)
		cout << -1 << endl;
	else
	{
		bool can = 0;
		for(int i = 1; !can && i <= n; i++)
			for(int j = 1; !can && j <= m; j++)
				if(check(i, j))
					can = 1;
		if(can || is == 1)
			cout << 1 << endl;
		else
			cout << 2 << endl;
	}
}


		//			- -- --- ---- -----be name khoda----- ---- --- -- -			\\

#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int a[N][N], n, m, is;
int x[] = {0, 0, 1, -1};
int y[] = {1, -1, 0, 0};
bool mark[N][N];

void dfs(int i, int j)
{
	mark[i][j] = 1;
	for(int mv = 0; mv < 4; mv++)
	{
		int ii = i + x[mv];
		int jj = j + y[mv];
		if(min(ii, jj) >= 1 && ii <= n && jj <= m)
			if(!mark[ii][jj] && a[ii][jj])
				dfs(ii, jj);
	}
}

bool check(int i, int j)
{
	if(!a[i][j])
		return 0;
	for(int k = 0; k <= n; k++)
		fill(mark[k], mark[k] + m + 1, 0);
	mark[i][j] = 1;
	bool done = 0;
	for(int k = 0; k < 4; k++)
	{
		int ii = i + x[k];
		int jj = j + y[k];
		if(min(ii, jj) >= 1 && ii <= n && jj <= m)
			if(a[ii][jj])
				if(!mark[ii][jj])
					if(!done)
					{
						dfs(ii, jj);
						done = 1;
					}
					else
						return 1;
	}
	return 0;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			char c;
			cin >> c;
			a[i][j] = (c == '#');
			is += a[i][j];
		}
	if(!is)
		cout << 0 << endl;
	else
	{
		bool can = 0;
		for(int i = 1; !can && i <= n; i++)
			for(int j = 1; !can && j <= m; j++)
				if(check(i, j))
					can = 1;
		if(can || is == 1)
			cout << 1 << endl;
		else
			cout << 2 << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
vector<int> p;
int n, m;
string s[55];

int find_set(int v) {
    if (p[v] == v)
        return v;
    return p[v] = find_set(p[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);

    if (rand() & 1)
        swap(a, b);

    p[a] = b;
}

char f() {
    p.clear();
    for (int i = 0; i < n * m; i++)
        p.push_back(i);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '.')
                continue;
            if (i)
                if (s[i - 1][j] == '#')
                    union_sets(i * m + j, (i - 1) * m + j);
            if (i + 1 < n)
                if (s[i + 1][j] == '#')
                    union_sets(i * m + j, (i + 1) * m + j);
            if (j)
                if (s[i][j - 1] == '#')
                    union_sets(i * m + j, i * m + j - 1);
            if (j + 1 < m)
                if (s[i][j + 1] == '#')
                    union_sets(i * m + j, i * m + j + 1);
        }

    int link = -1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '.')
                continue;
            if (link == -1)
                link = find_set(i * m + j);
            if (find_set(i * m + j) != link) {
                printf("1");
                return true;
            }
        }

    return false;
}

main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE

    scanf("%d%d\n", &n, &m);

    for (int i = 0; i < n; i++)
        getline(cin, s[i]);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '.')
                continue;
            s[i][j] = '.';
            if (f())
                return 0;
            s[i][j] = '#';
        }

    printf("2");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> p;
int n, m;
string s[55];

int find_set(int v) {
    if (p[v] == v)
        return v;
    return p[v] = find_set(p[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);

    if (rand() & 1)
        swap(a, b);

    p[a] = b;
}

char f() {
    p.clear();
    for (int i = 0; i < n * m; i++)
        p.push_back(i);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '.')
                continue;
            if (i)
                if (s[i - 1][j] == '#')
                    union_sets(i * m + j, (i - 1) * m + j);
            if (i + 1 < n)
                if (s[i + 1][j] == '#')
                    union_sets(i * m + j, (i + 1) * m + j);
            if (j)
                if (s[i][j - 1] == '#')
                    union_sets(i * m + j, i * m + j - 1);
            if (j + 1 < m)
                if (s[i][j + 1] == '#')
                    union_sets(i * m + j, i * m + j + 1);
        }

    int link = -1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '.')
                continue;
            if (link == -1)
                link = find_set(i * m + j);
            if (find_set(i * m + j) != link) {
                printf("1");
                return true;
            }
        }

    return false;
}

main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE

    scanf("%d%d\n", &n, &m);
    int magic_pony = 0;

    for (int i = 0; i < n; i++)
        getline(cin, s[i]);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '.')
                continue;
            s[i][j] = '.';
            if (f())
                return 0;
            s[i][j] = '#';
            magic_pony++;
        }

    printf(magic_pony < 3 ? "-1" : "2");

    return 0;
}


#ifndef SOURCE_IS_SPLICED
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef long double real;
void execute(); int main(){
  #ifdef twentyone
  freopen("a.in","r",stdin);
  #endif
  ios::sync_with_stdio(false);
  execute();
}
#endif

#include <cstring>

char buf[100][100];
int n,m;

bool done[100][100];
static int dx[4]={-1,0,1,0};
static int dy[4]={0,-1,0,1};

int search(int i,int j){
  if (done[i][j]==true) return -1;
  done[i][j]=true;

  int branches=0;
  for (int z=4; z--;){
    int u=i+dx[z];
    int v=j+dy[z];
    if (u>=0 and u<n and v>=0 and v<m and buf[u][v]=='#' and not done[u][v]){
      ++branches;
      search(u,v);
    }
  }
  return branches;
}

void execute(){
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>buf[i];

  int blocks=0; for (int i=n; i--;) for (int j=m; j--;) blocks+=(buf[i][j]=='#');
  if (blocks<=2) {cout<<"-1"<<endl;return;}

  int best=2;
  int a=0,b=0;
  for (int i=0; i<n; i++)
    for (int j=0; j<m; j++)
      if (buf[i][j]=='#'){
        memset(done,0,sizeof done);
        if (search(i,j)>1) best=1;
      }

  if (best==blocks) {cout<<"-1"<<endl;return;}
  cout<<best<<endl;
}


#ifndef SOURCE_IS_SPLICED
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef long double real;
void execute(); int main(){
  #ifdef twentyone
  freopen("a.in","r",stdin);
  #endif
  ios::sync_with_stdio(false);
  execute();
}
#endif

#include <cstring>

char buf[100][100];
int n,m;
/*
bool done[100][100];
void dfs(int i,int j){
  if (done[i][j]) return;
  done[i][j]=true;

  static int dx[4]={-1,0,1,0};
  static int dy[4]={0,-1,0,1};
  for (int z=4; z--;){
    int u=i+dx[z];
    int v=j+dy[z];
    if (u>=0 and u<n and v>=0 and v<m and buf[u][v]=='#') dfs(u,v);
  }
}
*/

bool done[100][100];
bool tree(int i,int j,int fi,int fj){
  if (done[i][j]) return false;
  done[i][j]=true;

  static int dx[4]={-1,0,1,0};
  static int dy[4]={0,-1,0,1};
  for (int z=4; z--;){
    int u=i+dx[z];
    int v=j+dy[z];
    if (u>=0 and u<n and v>=0 and v<m and (u!=fi or v!=fj) and buf[u][v]=='#' and not tree(u,v,i,j)) return false;
  }
  return true;
}

void execute(){
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>buf[i];

  int blocks=0; for (int i=n; i--;) for (int j=m; j--;) blocks+=(buf[i][j]=='#');
  if (blocks<=1) {cout<<"-1"<<endl;return;}

  int best=2;

  int a=0,b=0;
  for (int i=0; i<n; i++)
    for (int j=0; j<m; j++)
      if (buf[i][j]=='#'){

        if (tree(i,j,-1,-1)) best=1;

/*
        int deg=0,cnt=0;
        memset(done,0,sizeof done); done[i][j]=true;
        if (i>0   and buf[i-1][j]=='#') {if (not done[i-1][j]) dfs(i-1,j), ++cnt; else ++deg;}
        if (i+1<n and buf[i+1][j]=='#') {if (not done[i+1][j]) dfs(i+1,j), ++cnt; else ++deg;}
        if (j>0   and buf[i][j-1]=='#') {if (not done[i][j-1]) dfs(i,j-1), ++cnt; else ++deg;}
        if (j+1<m and buf[i][j+1]=='#') {if (not done[i][j+1]) dfs(i,j+1), ++cnt; else ++deg;}
//        cout<<i<<" "<<j<<" : "<<deg<<" "<<cnt<<endl;
        if (deg==0 or cnt>1) best=min(best,1);
        best=min(best,cnt+deg);
*/
      }

  if (best==blocks) {cout<<"-1"<<endl;return;}
  cout<<best<<endl;
}


#ifndef SOURCE_IS_SPLICED
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef long double real;
void execute(); int main(){
  #ifdef twentyone
  freopen("a.in","r",stdin);
  #endif
  ios::sync_with_stdio(false);
  execute();
}
#endif

#include <cstring>

char buf[100][100];
int n,m;

bool done[100][100];
void dfs(int i,int j){
  if (done[i][j]) return;
  done[i][j]=true;

  static int dx[4]={-1,0,1,0};
  static int dy[4]={0,-1,0,1};
  for (int z=4; z--;){
    int u=i+dx[z];
    int v=j+dy[z];
    if (u>=0 and u<n and v>=0 and v<m and buf[u][v]=='#') dfs(u,v);
  }
}

void execute(){
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>buf[i];

  int blocks=0; for (int i=n; i--;) for (int j=m; j--;) blocks+=(buf[i][j]=='#');
  if (blocks<=1) {cout<<"-1"<<endl;return;}

  int best=100;

  int a=0,b=0;
  for (int i=0; i<n; i++)
    for (int j=0; j<m; j++)
      if (buf[i][j]=='#'){

        int deg=0,cnt=0;
        memset(done,0,sizeof done); done[i][j]=true;
        if (i>0   and buf[i-1][j]=='#') {if (not done[i-1][j]) dfs(i-1,j), ++cnt; else ++deg;}
        if (i+1<n and buf[i+1][j]=='#') {if (not done[i+1][j]) dfs(i+1,j), ++cnt; else ++deg;}
        if (j>0   and buf[i][j-1]=='#') {if (not done[i][j-1]) dfs(i,j-1), ++cnt; else ++deg;}
        if (j+1<m and buf[i][j+1]=='#') {if (not done[i][j+1]) dfs(i,j+1), ++cnt; else ++deg;}
        if (deg==0 or cnt>1) best=min(best,1);
        best=min(best,cnt+deg);
      }

  if (best==blocks) {cout<<"-1"<<endl;return;}
  cout<<best<<endl;
}


#ifndef SOURCE_IS_SPLICED
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef long double real;
void execute(); int main(){
  #ifdef twentyone
  freopen("a.in","r",stdin);
  #endif
  ios::sync_with_stdio(false);
  execute();
}
#endif

char buf[100][100];
int n,m;

bool dfs(int i,int j,int fi=-1,int fj=-1){
  if (buf[i][j]==0) return true;
  buf[i][j]=0;

  static int dx[4]={-1,0,1,0};
  static int dy[4]={0,-1,0,1};
  for (int z=4; z--;){
    int u=i+dx[z];
    int v=j+dy[z];
    if (u>=0 and u<n and v>=0 and v<n and (u!=fi or v!=fj) and dfs(u,v)) return true;
  }
  return false;
}

void execute(){
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>buf[i];

  int blocks=0; for (int i=n; i--;) for (int j=m; j--;) blocks+=(buf[i][j]=='#');
  if (blocks<=1) {cout<<"-1"<<endl;return;}

  int best=100;

  int a=0,b=0;
  for (int i=0; i<n; i++)
    for (int j=0; j<m; j++)
      if (buf[i][j]=='#'){
        int deg=0;
        if (i>0   and buf[i-1][j]=='#') ++deg;
        if (i+1<n and buf[i+1][j]=='#') ++deg;
        if (j>0   and buf[i][j-1]=='#') ++deg;
        if (j+1<m and buf[i][j+1]=='#') ++deg;
        best=min(best,deg);
        a=i,b=j;
      }

  if (not dfs(a,b)) best=min(best,1);
  if (best==blocks) {cout<<"-1"<<endl;return;}
  cout<<best<<endl;
}


#ifndef SOURCE_IS_SPLICED
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef long double real;
void execute(); int main(){
  #ifdef twentyone
  freopen("a.in","r",stdin);
  #endif
  ios::sync_with_stdio(false);
  execute();
}
#endif

#include <cstring>

char buf[100][100];
int n,m;

bool done[100][100];
void dfs(int i,int j){
  if (done[i][j]) return;
  done[i][j]=true;

  static int dx[4]={-1,0,1,0};
  static int dy[4]={0,-1,0,1};
  for (int z=4; z--;){
    int u=i+dx[z];
    int v=j+dy[z];
    if (u>=0 and u<n and v>=0 and v<n and buf[u][v]=='#') dfs(u,v);
  }
}

void execute(){
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>buf[i];

  int blocks=0; for (int i=n; i--;) for (int j=m; j--;) blocks+=(buf[i][j]=='#');
  if (blocks<=1) {cout<<"-1"<<endl;return;}

  int best=100;

  int a=0,b=0;
  for (int i=0; i<n; i++)
    for (int j=0; j<m; j++)
      if (buf[i][j]=='#'){

        int deg=0,cnt=0;
        memset(done,0,sizeof done); done[i][j]=true;
        if (i>0   and buf[i-1][j]=='#') {if (not done[i-1][j]) dfs(i-1,j), ++cnt; else ++deg;}
        if (i+1<n and buf[i+1][j]=='#') {if (not done[i+1][j]) dfs(i+1,j), ++cnt; else ++deg;}
        if (j>0   and buf[i][j-1]=='#') {if (not done[i][j-1]) dfs(i,j-1), ++cnt; else ++deg;}
        if (j+1<m and buf[i][j+1]=='#') {if (not done[i][j+1]) dfs(i,j+1), ++cnt; else ++deg;}
        if (deg==0) best=min(best,1);
        best=min(best,cnt+deg);
      }

  if (best==blocks) {cout<<"-1"<<endl;return;}
  cout<<best<<endl;
}


#ifndef SOURCE_IS_SPLICED
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef long double real;
void execute(); int main(){
  #ifdef twentyone
  freopen("a.in","r",stdin);
  #endif
  ios::sync_with_stdio(false);
  execute();
}
#endif

#include <cstring>

char buf[100][100];
int n,m;

bool done[100][100];
bool tree(int i,int j,int fi,int fj){
  if (done[i][j]) return false;
  done[i][j]=true;

  static int dx[4]={-1,0,1,0};
  static int dy[4]={0,-1,0,1};
  for (int z=4; z--;){
    int u=i+dx[z];
    int v=j+dy[z];
    if (u>=0 and u<n and v>=0 and v<m and (u!=fi or v!=fj) and buf[u][v]=='#' and not tree(u,v,i,j)) return false;
  }
  return true;
}

void execute(){
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>buf[i];

  int blocks=0; for (int i=n; i--;) for (int j=m; j--;) blocks+=(buf[i][j]=='#');
  if (blocks<=1) {cout<<"-1"<<endl;return;}

  int best=2;

  int a=0,b=0;
  if (blocks>2)
  for (int i=0; i<n; i++)
    for (int j=0; j<m; j++)
      if (buf[i][j]=='#'){
        memset(done,0,sizeof done);
        if (tree(i,j,-1,-1)) best=1;
      }

  if (best==blocks) {cout<<"-1"<<endl;return;}
  cout<<best<<endl;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <string.h>
#include <bitset>
#include <queue>
#include <functional>
#include <stack>
#include <sstream>
#include <list>

#define LOOP(i,n) for(int i=0; i<n;i++)
#define TESTCASE int T;cin >>T;for(int Z=0;Z<T;Z++)
#define ARRIN(i,n) for(int il=0;il<n;il++)cin>>i[il]
#define OO (int)1e9
#define CLR(arr,num) memset(arr,num,sizeof(arr))
#define CLR2(arr,num,size) for(int i=0;i<size;i++)arr[i]=num;
#define SUM(arr,n,s) for(int i=0;i<n;i++)s+=arr[i];
#define BWGET(code,i) (code & (1 << i))
#define BWSET(code,i,s) ((s)?code|(1<<i):code&(~(1<<i)))
#define EPS 1e-9

using namespace std;

vector<vector<int> > G;

int dx[] = {1,-1,0,0},
    dy[] = {0,0,1,-1};

bool vis[2500];
int c;

void dfs(int n){
    c++;
    vis[n]=1;
    for (int i = 0; i < G[n].size(); i++)
    {
        if(!vis[G[n][i]])
            dfs(G[n][i]);
    }
}

int main(){
    int n,m; cin >> n >> m;
    vector<string> v(n);
    int hsh = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        for (int j = 0; j < m; j++)
        {
            hsh += v[i][j] == '#';
        }
    }
    G.resize(hsh);
    map<int,int> mp;
    int I = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if(v[i][j] == '#'){
                if(mp.count(i*m+j) == 0)
                    mp[i*m+j] = I++;
                for (int k = 0; k < 4; k++)
                {
                    int ni,nj;
                    ni = i+dy[k],nj = j+dx[k];
                    if(ni < 0 || nj < 0 || ni >= n || nj >= m || v[ni][nj] != '#')continue;
                    if(mp.count(ni*m+nj) == 0)
                        mp[ni*m+nj] = I++;
                    G[mp[i*m+j]].push_back(mp[ni*m+nj]);
                }
            }
        }
    }
    if(hsh <= 2){
        cout << -1;
        return 0;
    }
    bool isCrit = 0;
    for (int i = 0; i < hsh; i++)
    {
        CLR(vis,0);
        vis[i] = 1;
        c = 1;
        if(i)
            dfs(0);
        else
            dfs(1);
        if(c < hsh){
            isCrit=1;
            break;
        }
    }
    if(isCrit)
        cout << 1;
    else
        cout << 2;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

template<typename T> inline void minimize(T &a, T b) { a = std::min(a, b); }
template<typename T> inline void maximize(T &a, T b) { a = std::max(a, b); }

#define all(v) v.begin(),v.end()

using namespace std;

#define endl '\n'
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;
#define nextVector(t, v, size) vector< argument_type<void(t)>::type > v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

#define range(name, start, count) vector<int> name(count); { for (int i = 0 ; i < count ; i++) name[i] = i + start; }

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) os << v[i] << ' '; os << endl; return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

int main() {
	srand (time(NULL));
    ios_base::sync_with_stdio(false); cin.tie(NULL);

	next(int, n);
	next(int, m);

	auto f = readVector<string>(n);
	int cnt = 0;
	FOR (i, 0, n) FOR (j, 0, m) if (f[i][j] == '#') cnt++;
	if (cnt <= 2) {
		cout << -1;
		return 0;
	}
	vector<pair<int, int>> q;

	auto enq = [&](int x, int y) {
		if (x < 0 || y < 0 || x >= n || y >= m) return;
		if (f[x][y] != '#') return;
		f[x][y] = '+';
		q.push_back(make_pair(x, y));
	};

	FOR (i, 0, n) FOR (j, 0, m) if (f[i][j] == '#') {
		f[i][j] = '.';
		int sx, sy;
		FOR (i2, 0, n) FOR (j2, 0, m) if (f[i2][j2] == '#') { sx = i2; sy = j2; }

		q.clear();
		enq(sx, sy);
		FOR (k, 0, q.size()) {
			auto x = q[k].first;
			auto y = q[k].second;
			enq(x - 1, y);
			enq(x + 1, y);
			enq(x, y - 1);
			enq(x, y + 1);
		}
		FOR (i2, 0, n) FOR (j2, 0, m)
			if (f[i2][j2] == '#') {
				cout << 1;
				return 0;
			} else if (f[i2][j2] == '+') f[i2][j2] = '#';

		f[i][j] = '#';
	}

	cout << 2;
}


// In The Name Of God

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sz(x) ((int)x.size())
#define mp make_pair
#define Maxn 100
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef long double dd;
char a[Maxn][Maxn];
int xx[] = {0,1,0,-1};
int yy[] = {1,0,-1,0};
int vis[Maxn][Maxn];
int n, m;
int dfs(int x,int y)
{
    //cerr << x <<' '<< y << endl;
    if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == '.' || vis[x][y])
        return 0;
    vis[x][y] = 1;
    rep(i,4){
        x += xx[i], y += yy[i];
        if(!(x < 0 || y < 0 || x >= n || y >= m || a[x][y] == '.' || vis[x][y]))
        dfs( x , y);
        x -= xx[i], y -= yy[i];
    }
    return 1;
}

int main()
{_
    cin >> n >> m;
    int ans = 0;
    rep(i,n) rep(j,m) cin >> a[i][j];
    rep(i,n) rep(j,m) if(a[i][j] == '#'){
        ans++;
        a[i][j] = '.';
        memset(vis,0,sizeof(vis));
        int reg = 0;
        rep(k,4){
            reg += dfs(i+xx[k], j+yy[k]);
            //cerr << reg;
        }
        if (reg > 1) {
            cout << 1; return 0;
        }
        a[i][j]='#';
    }
    if (ans < 3) cout << -1;
    else cout << 2;
}


// In The Name Of God

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 1; i <= (n); i++)
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sz(x) ((int)x.size())
#define mp make_pair
#define Maxn 100
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef long double dd;
char a[Maxn][Maxn];
int xx[] = {0,1,0,-1};
int yy[] = {1,0,-1,0};

int main()
{_
    int n, m; cin >> n >> m;
    int ans = 0, mn = 10;
    rep(i,n) rep(j,m) cin >> a[i][j];
    rep(i,n) rep(j,m) if(a[i][j] == '#'){
        ans ++;
        int dig = 0;
        rep(k,4){
            if (a[i+xx[k-1]][j+yy[k-1]] == '#')
                dig++;
        }
        mn = min(mn,dig);
    }
    if (ans < 2) cout << -1;
    else cout << mn;
}


// In The Name Of God

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sz(x) ((int)x.size())
#define mp make_pair
#define Maxn 100
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef long double dd;
char a[Maxn][Maxn];
int xx[] = {0,1,0,-1};
int yy[] = {1,0,-1,0};
int vis[Maxn][Maxn];
int n, m;
int dfs(int x,int y)
{
    if (x < 0 || y < 0 || x >= m || y >= n || a[x][y] == '.' || vis[x][y])
        return 0;
    vis[x][y] = 1;
    rep(i,4)
        dfs(x+xx[i], y+yy[i]);
    return 1;
}

int main()
{_
    cin >> n >> m;
    int ans = 0;
    rep(i,n) rep(j,m) cin >> a[i][j];
    rep(i,n) rep(j,m) if(a[i][j] == '#'){
        ans++;
        a[i][j]='.';
        memset(vis,0,sizeof(vis));
        int reg = 0;
        rep(k,4)
            reg += dfs(i+xx[k], j+yy[k]);
        if (reg>1) {
            cout << 1; return 0;
        }
        a[i][j]='#';
    }
    if (ans < 3) cout << -1;
    else cout << 2;
}


// In The Name Of God

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 1; i <= (n); i++)
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sz(x) ((int)x.size())
#define mp make_pair
#define Maxn 100
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef long double dd;
char a[Maxn][Maxn];
int xx[] = {0,1,0,-1};
int yy[] = {1,0,-1,0};

int main()
{_
    int n, m; cin >> n >> m;
    int ans = 0, mn = 10;
    rep(i,n) rep(j,m) cin >> a[i][j];
    rep(i,n) rep(j,n) if(a[i][j] == '#'){
        ans ++;
        int dig = 0;
        rep(k,4){
            if (a[i+xx[k-1]][j+yy[k-1]] == '#')
                dig++;
        }
        mn = min(mn,dig);
    }
    if (ans < 2) cout << -1;
    else cout << mn;
}


//Karol Kaszuba
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <cstdlib>
#include <ctime>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double D;
typedef long double LD;
typedef vector<PII> VII;

#define FOR(i,x,y) for(int i=(x);i<=(y);++i)
#define REP(i,x) FOR(i,0,(x)-1)
#define FORD(i,x,y) for(int i=(x);i>=(y);--i)
#define VAR(i,c) __typeof(c) i=(c)
#define FORE(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)

#define SIZE(c) (int)((c).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN insert
#define ER erase
#define MP make_pair
#define ST first
#define ND second
#define IOSYNC ios_base::sync_with_stdio(0)

int tab[55][55];

void dfs(int a, int b)
{
	if(tab[a][b] > 1)
		return;
	if(tab[a][b] < 1)
		return;
	tab[a][b] = 2;
	dfs(a - 1, b);
	dfs(a + 1, b);
	dfs(a, b - 1);
	dfs(a, b + 1);
}

void hops(int n, int m)
{
	FOR(i, 1, n)
		FOR(j, 1, m)
		{
			if(tab[i][j] == 1)
			{
				dfs(i, j);
				return;
			}
		}

}
bool czek(int n, int m, int ile)
{
	int wyn = 0;
	hops(n, m);
	FOR(i, 1, n)
		FOR(j, 1, m)
			if(tab[i][j] > 1)
			{
				tab[i][j] = 1;
				wyn++;
			}
	if(wyn != ile - 1)
		return true;
	return false;
}

void jebaj()
{
	int n, m, ile;
	cin >> n >> m;
	REP(i, n)
	{
		string s;
		cin >> s;
		REP(j, m)
		{
			tab[i + 1][j + 1] = (s[j] == '#');
			ile += tab[i + 1][j + 1];
		}
	}

	if(ile == 1 || ile == 2)
	{
		cout << "-1\n";
		return;
	}

	REP(i, n)
		REP(j, m)
		{
			if(tab[i + 1][j + 1])
			{
				tab[i + 1][j + 1] = 0;
				if(czek(n, m, ile))
				{
					cout << "1\n";
					return;
				}
				tab[i + 1][j + 1] = 1;
			}
		}
	cout << "2\n";
	return;
}

int main()
{
	IOSYNC;
	int t;
	t = 1;
	//cin >> t;

	REP(i, t)
	{
		jebaj();
	}
}


#include <cstdio>

#define maxn 64

int m, n, num = 0, res;
int pp[maxn][maxn];
int used[maxn][maxn];
char cur;

void input_data(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			scanf(" %c", &cur);
			pp[i][j] = (cur == '.') ? 0 : 1;
			num += pp[i][j];
		}
}

void DFS(const int &dx, const int &dy, const int &size){
	used[dx][dy] = size;
	if(dy > 0 && pp[dx][dy - 1] && !used[dx][dy - 1])DFS(dx, dy - 1, size);
	if(dy < m - 1 && pp[dx][dy + 1] && !used[dx][dy + 1])DFS(dx, dy + 1, size);
	if(dx > 0 && pp[dx - 1][dy] && !used[dx - 1][dy])DFS(dx - 1, dy, size);
	if(dx < n - 1 && pp[dx + 1][dy] && !used[dx + 1][dy])DFS(dx + 1, dy, size);
}

bool DFS1(){
	for(int i = 0; i < maxn; ++i)
		for(int j = 0; j < maxn; ++j)
			used[i][j] = 0;
	int col = 0;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(pp[i][j] && !used[i][j])DFS(i, j, ++col);
	return(col < 2);
}

void o_n(const int &xx){printf("%d\n", xx);}

int calc(){
	res = -1;
	if(num > 2){
		res = 1;
		for(int i = 0; i < n; ++i)
			for(int j = 0; j < m; ++j)
				if(pp[i][j]){
					pp[i][j] = 0;
					if(!DFS1())return 0;
					pp[i][j] = 1;
				}
		res = 2;
	}
	return 0;
}

int main(){
	input_data();
	calc();
	o_n(res);
	return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <functional>
#include <string>
#include <algorithm>

#include <cstring>
#include <cstdio>
#include <memory.h>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>

#define eps e-8

using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i,a,b) for(int i = int(a); i <= int(b); i++)

#define foreach(it,a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define mp make_pair
#define pb push_back
#define L(s) ((int)((s).size()))
#define sq(x) ((x)*(x))

#define sign(x) ( ((x) > 0) ? 1 : -1)
#define ll long long
#define INF 1000000000

#define MAXN 100010

bool connect(vector<string> &v)
{
    int n=v.size();
    int m=v[0].size();
    vector<vector<int> > used(n);
    forn(i, n)
        used[i].resize(m);
    int fxs =0, fys=0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#') {
                used[i][j] = 0;
                fxs = i;
                fys = j;
            }
            else
                used[i][j]=-1;
        }
    queue<pair<int, int> > proc;
    proc.push(mp(fxs, fys));
    int cnt =0;
    while(proc.size()!=0)
    {
        cnt++;
        if(cnt>10000)
        {
            return false;
        }
        pair<int, int> cur = proc.front();
        int fx=cur.first;
        int fy=cur.second;
        proc.pop();
        used[fx][fy]=1;
        fore(dx, -1, 1)
            fore(dy, -1, 1)
            {
                if((abs(dx)+abs(dy))!=1)
                    continue;
                if(fx+dx>=0 && fx+dx<n && fy+dy>=0 && fy+dy<m && used[fx+dx][fy+dy]==0)
                {
                    proc.push(mp(fx+dx, fy+dy));
                }
            }
    }
    forn(i, n)
        forn(j, m)
        {
            if(used[i][j]==0)
                return false;
        }
    return true;
}

void solveA()
{
    int n, m;
    cin>>n>>m;
    vector<string> v(n);
    forn(i, n)
    {
        cin>>v[i];
    }
    int cnt =0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#')
            {
                cnt++;
                v[i][j]='.';
                if(!connect(v))
                {
                    cout<<"1"<<endl;
                    return;
                }
                v[i][j]='#';
            }
        }
    if(cnt<3)
    {
        cout<<"-1"<<endl;
        return;
    }
    cout<<"2"<<endl;
}

int main()
{
#ifdef diametralis
    freopen("/Users/diametralis/Documents/projects/IO/input.txt", "rt", stdin);
    //freopen("/Users/diametralis/Documents/projects/IO/output.txt", "wt", stdout);
#endif
    solveA();
#ifdef diametralis
    cerr << "Time == " << clock() << endl;
#endif
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <functional>
#include <string>
#include <algorithm>

#include <cstring>
#include <cstdio>
#include <memory.h>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>

#define eps e-8

using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i,a,b) for(int i = int(a); i <= int(b); i++)

#define foreach(it,a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define mp make_pair
#define pb push_back
#define L(s) ((int)((s).size()))
#define sq(x) ((x)*(x))

#define sign(x) ( ((x) > 0) ? 1 : -1)
#define ll long long
#define INF 1000000000

#define MAXN 100010

bool connect(vector<string> &v)
{
    int n=v.size();
    int m=v[0].size();
    vector<vector<int> > used(n);
    forn(i, n)
        used[i].resize(m);
    int fxs =0, fys=0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#') {
                used[i][j] = 0;
                fxs = i;
                fys = j;
            }
            else
                used[i][j]=-1;
        }
    queue<pair<int, int> > proc;
    proc.push(mp(fxs, fys));
    int cnt =0;
    while(proc.size()!=0)
    {
        cnt++;
        if(cnt>1000000)
        {
            return false;
        }
        pair<int, int> cur = proc.front();
        int fx=cur.first;
        int fy=cur.second;
        proc.pop();
        used[fx][fy]=1;
        fore(dx, -1, 1)
            fore(dy, -1, 1)
            {
                if((abs(dx)+abs(dy))!=1)
                    continue;
                if(fx+dx>=0 && fx+dx<n && fy+dy>=0 && fy+dy<m && used[fx+dx][fy+dy]==0)
                {
                    proc.push(mp(fx+dx, fy+dy));
                }
            }
    }
    forn(i, n)
        forn(j, m)
        {
            if(used[i][j]==0)
                return false;
        }
    return true;
}

void solveA()
{
    int n, m;
    cin>>n>>m;
    vector<string> v(n);
    forn(i, n)
    {
        cin>>v[i];
    }
    int cnt =0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#')
            {
                cnt++;
                v[i][j]='.';
                if(!connect(v))
                {
                    cout<<"1"<<endl;
                    return;
                }
                v[i][j]='#';
            }
        }
    if(cnt<3)
    {
        cout<<"-1"<<endl;
        return;
    }
    cout<<"2"<<endl;
}

int main()
{
#ifdef diametralis
    freopen("/Users/diametralis/Documents/projects/IO/input.txt", "rt", stdin);
    //freopen("/Users/diametralis/Documents/projects/IO/output.txt", "wt", stdout);
#endif
    solveA();
#ifdef diametralis
    cerr << "Time == " << clock() << endl;
#endif
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <functional>
#include <string>
#include <algorithm>

#include <cstring>
#include <cstdio>
#include <memory.h>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>

#define eps e-8

using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i,a,b) for(int i = int(a); i <= int(b); i++)

#define foreach(it,a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define mp make_pair
#define pb push_back
#define L(s) ((int)((s).size()))
#define sq(x) ((x)*(x))

#define sign(x) ( ((x) > 0) ? 1 : -1)
#define ll long long
#define INF 1000000000

#define MAXN 100010

bool connect(vector<string> &v)
{
    int n=v.size();
    int m=v[0].size();
    vector<vector<int> > used(n);
    forn(i, n)
        used[i].resize(m);
    int fxs =0, fys=0;
    forn(i, n)
        forn(j, n)
        {
            if(v[i][j]=='#') {
                used[i][j] = 0;
                fxs = i;
                fys = j;
            }
            else
                used[i][j]=-1;
        }
    queue<pair<int, int> > proc;
    proc.push(mp(fxs, fys));
    while(proc.size()!=0)
    {
        pair<int, int> cur = proc.front();
        int fx=cur.first;
        int fy=cur.second;
        proc.pop();
        used[fx][fy]=1;
        fore(dx, -1, 1)
            fore(dy, -1, 1)
            {
                if(abs(dx)+abs(dy)!=1)
                    continue;
                if(fx+dx>=0 && fx+dx<n && fy+dy>=0 && fy+dy<m && used[fx+dx][fy+dy]==0)
                {
                    proc.push(mp(fx+dx, fy+dy));
                }
            }
    }
    forn(i, n)
        forn(j, n)
        {
            if(used[i][j]==0)
                return false;
        }
    return true;
}

void solveA()
{
    int n, m;
    cin>>n>>m;
    vector<string> v(n);
    forn(i, n)
    {
        cin>>v[i];
    }
    int cnt =0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#')
            {
                cnt++;
                v[i][j]='.';
                v[i][j]='#';
                //if(!connect(v))
                //{
                //    cout<<"1"<<endl;
                //    return;
                //}
            }
        }
    if(cnt<3)
    {
        cout<<"-1"<<endl;
        return;
    }
    cout<<"2"<<endl;
}

int main()
{
#ifdef diametralis
    freopen("/Users/diametralis/Documents/projects/IO/input.txt", "rt", stdin);
    //freopen("/Users/diametralis/Documents/projects/IO/output.txt", "wt", stdout);
#endif
    solveA();
#ifdef diametralis
    cerr << "Time == " << clock() << endl;
#endif
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <functional>
#include <string>
#include <algorithm>

#include <cstring>
#include <cstdio>
#include <memory.h>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>

#define eps e-8

using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i,a,b) for(int i = int(a); i <= int(b); i++)

#define foreach(it,a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define mp make_pair
#define pb push_back
#define L(s) ((int)((s).size()))
#define sq(x) ((x)*(x))

#define sign(x) ( ((x) > 0) ? 1 : -1)
#define ll long long
#define INF 1000000000

#define MAXN 100010

bool connect(vector<string> &v)
{
    int n=v.size();
    int m=v[0].size();
    vector<vector<int> > used(n);
    forn(i, n)
        used[i].resize(m);
    int fxs =0, fys=0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#') {
                used[i][j] = 0;
                fxs = i;
                fys = j;
            }
            else
                used[i][j]=-1;
        }
    queue<pair<int, int> > proc;
    proc.push(mp(fxs, fys));
    while(proc.size()!=0)
    {
        pair<int, int> cur = proc.front();
        int fx=cur.first;
        int fy=cur.second;
        proc.pop();
        used[fx][fy]=1;
        fore(dx, -1, 1)
            fore(dy, -1, 1)
            {
                if(abs(dx)+abs(dy)!=1)
                    continue;
                if(fx+dx>=0 && fx+dx<n && fy+dy>=0 && fy+dy<m && used[fx+dx][fy+dy]==0)
                {
                    proc.push(mp(fx+dx, fy+dy));
                }
            }
    }
    forn(i, n)
        forn(j, m)
        {
            if(used[i][j]==0)
                return false;
        }
    return true;
}

void solveA()
{
    int n, m;
    cin>>n>>m;
    vector<string> v(n);
    forn(i, n)
    {
        cin>>v[i];
    }
    int cnt =0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#')
            {
                cnt++;
                v[i][j]='.';
                if(!connect(v))
                {
                    cout<<"1"<<endl;
                    return;
                }
                v[i][j]='#';
            }
        }
    if(cnt<3)
    {
        cout<<"-1"<<endl;
        return;
    }
    cout<<"2"<<endl;
}

int main()
{
#ifdef diametralis
    freopen("/Users/diametralis/Documents/projects/IO/input.txt", "rt", stdin);
    //freopen("/Users/diametralis/Documents/projects/IO/output.txt", "wt", stdout);
#endif
    solveA();
#ifdef diametralis
    cerr << "Time == " << clock() << endl;
#endif
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <functional>
#include <string>
#include <algorithm>

#include <cstring>
#include <cstdio>
#include <memory.h>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>

#define eps e-8

using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i,a,b) for(int i = int(a); i <= int(b); i++)

#define foreach(it,a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define mp make_pair
#define pb push_back
#define L(s) ((int)((s).size()))
#define sq(x) ((x)*(x))

#define sign(x) ( ((x) > 0) ? 1 : -1)
#define ll long long
#define INF 1000000000

#define MAXN 100010

bool connect(vector<string> &v)
{
    int n=v.size();
    int m=v[0].size();
    vector<vector<int> > used(n);
    forn(i, n)
        used[i].resize(m);
    int fxs =0, fys=0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#') {
                used[i][j] = 0;
                fxs = i;
                fys = j;
            }
            else
                used[i][j]=-1;
        }
    queue<pair<int, int> > proc;
    proc.push(mp(fxs, fys));
    while(proc.size()!=0)
    {
        pair<int, int> cur = proc.front();
        int fx=cur.first;
        int fy=cur.second;
        proc.pop();
        used[fx][fy]=1;
        fore(dx, -1, 1)
            fore(dy, -1, 1)
            {
                if((abs(dx)+abs(dy))!=1)
                    continue;
                if(fx+dx>=0 && fx+dx<n && fy+dy>=0 && fy+dy<m && used[fx+dx][fy+dy]==0)
                {
                    proc.push(mp(fx+dx, fy+dy));
                }
            }
    }
    forn(i, n)
        forn(j, m)
        {
            if(used[i][j]==0)
                return false;
        }
    return true;
}

void solveA()
{
    int n, m;
    cin>>n>>m;
    vector<string> v(n);
    forn(i, n)
    {
        cin>>v[i];
    }
    int cnt =0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#')
            {
                cnt++;
                v[i][j]='.';
                if(!connect(v))
                {
                    cout<<"1"<<endl;
                    return;
                }
                v[i][j]='#';
            }
        }
    if(cnt<3)
    {
        cout<<"-1"<<endl;
        return;
    }
    cout<<"2"<<endl;
}

int main()
{
#ifdef diametralis
    freopen("/Users/diametralis/Documents/projects/IO/input.txt", "rt", stdin);
    //freopen("/Users/diametralis/Documents/projects/IO/output.txt", "wt", stdout);
#endif
    solveA();
#ifdef diametralis
    cerr << "Time == " << clock() << endl;
#endif
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <functional>
#include <string>
#include <algorithm>

#include <cstring>
#include <cstdio>
#include <memory.h>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>

#define eps e-8

using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i,a,b) for(int i = int(a); i <= int(b); i++)

#define foreach(it,a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define mp make_pair
#define pb push_back
#define L(s) ((int)((s).size()))
#define sq(x) ((x)*(x))

#define sign(x) ( ((x) > 0) ? 1 : -1)
#define ll long long
#define INF 1000000000

#define MAXN 100010

bool connect(vector<string> &v)
{
    int n=v.size();
    int m=v[0].size();
    vector<vector<int> > used(n);
    forn(i, n)
        used[i].resize(m);
    int fxs =0, fys=0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#') {
                used[i][j] = 0;
                fxs = i;
                fys = j;
            }
            else
                used[i][j]=-1;
        }
    queue<pair<int, int> > proc;
    proc.push(mp(fxs, fys));
    used[fxs][fys]=1;
    int cnt =0;
    while(proc.size()!=0)
    {
        pair<int, int> cur = proc.front();
        int fx=cur.first;
        int fy=cur.second;
        proc.pop();
        fore(dx, -1, 1)
            fore(dy, -1, 1)
            {
                if((abs(dx)+abs(dy))!=1)
                    continue;
                if(fx+dx>=0 && fx+dx<n && fy+dy>=0 && fy+dy<m && used[fx+dx][fy+dy]==0)
                {
                    proc.push(mp(fx+dx, fy+dy));
                    used[fx+dx][fy+dy]=1;
                }
            }
    }
    forn(i, n)
        forn(j, m)
        {
            if(used[i][j]==0)
                return false;
        }
    return true;
}

void solveA()
{
    int n, m;
    cin>>n>>m;
    vector<string> v(n);
    forn(i, n)
    {
        cin>>v[i];
    }
    int cnt =0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#')
            {
                cnt++;
                v[i][j]='.';
                if(!connect(v))
                {
                    cout<<"1"<<endl;
                    return;
                }
                v[i][j]='#';
            }
        }
    if(cnt<3)
    {
        cout<<"-1"<<endl;
        return;
    }
    cout<<"2"<<endl;
}

int main()
{
#ifdef diametralis
    freopen("/Users/diametralis/Documents/projects/IO/input.txt", "rt", stdin);
    //freopen("/Users/diametralis/Documents/projects/IO/output.txt", "wt", stdout);
#endif
    solveA();
#ifdef diametralis
    cerr << "Time == " << clock() << endl;
#endif
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <functional>
#include <string>
#include <algorithm>

#include <cstring>
#include <cstdio>
#include <memory.h>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>

#define eps e-8

using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i,a,b) for(int i = int(a); i <= int(b); i++)

#define foreach(it,a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define mp make_pair
#define pb push_back
#define L(s) ((int)((s).size()))
#define sq(x) ((x)*(x))

#define sign(x) ( ((x) > 0) ? 1 : -1)
#define ll long long
#define INF 1000000000

#define MAXN 100010

bool connect(vector<string> &v)
{
    int n=v.size();
    int m=v[0].size();
    vector<vector<int> > used(n);
    forn(i, n)
        used[i].resize(m);
    int fxs =0, fys=0;
    forn(i, n)
        forn(j, n)
        {
            if(v[i][j]=='#') {
                used[i][j] = 0;
                fxs = i;
                fys = j;
            }
            else
                used[i][j]=-1;
        }
    queue<pair<int, int> > proc;
    proc.push(mp(fxs, fys));
    while(proc.size()!=0)
    {
        pair<int, int> cur = proc.front();
        int fx=cur.first;
        int fy=cur.second;
        proc.pop();
        used[fx][fy]=1;
        fore(dx, -1, 1)
            fore(dy, -1, 1)
            {
                if(abs(dx)+abs(dy)!=1)
                    continue;
                if(fx+dx>=0 && fx+dx<n && fy+dy>=0 && fy+dy<m && used[fx+dx][fy+dy]==0)
                {
                    proc.push(mp(fx+dx, fy+dy));
                }
            }
    }
    forn(i, n)
        forn(j, n)
        {
            if(used[i][j]==0)
                return false;
        }
    return true;
}

void solveA()
{
    int n, m;
    cin>>n>>m;
    vector<string> v(n);
    forn(i, n)
    {
        cin>>v[i];
    }
    int cnt =0;
    forn(i, n)
        forn(j, m)
        {
            if(v[i][j]=='#')
            {
                cnt++;
                v[i][j]='.';
                if(!connect(v))
                {
                    cout<<"1"<<endl;
                    return;
                }
                v[i][j]='#';
            }
        }
    if(cnt<3)
    {
        cout<<"-1"<<endl;
        return;
    }
    cout<<"2"<<endl;
}

int main()
{
#ifdef diametralis
    freopen("/Users/diametralis/Documents/projects/IO/input.txt", "rt", stdin);
    //freopen("/Users/diametralis/Documents/projects/IO/output.txt", "wt", stdout);
#endif
    solveA();
#ifdef diametralis
    cerr << "Time == " << clock() << endl;
#endif
}


#include <iostream>
#include <vector>
using namespace std;
int n,m,s;
int neigh[60][60];
vector<string> grid;
bool lives(int r, int c){
	if(r<0||c<0||r>=n||c>=m)
		return 0;
	return grid[r][c]=='#';
}
int main(){
	cin >> n >> m;
	grid.resize(n);
	for(int i = 0; i < n; ++i)
		cin >> grid[i];
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				s++;
	if(s<=2){
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			if(lives(i,j)){
				neigh[i][j]+=lives(i+1,j);
				neigh[i][j]+=lives(i-1,j);
				neigh[i][j]+=lives(i,j+1);
				neigh[i][j]+=lives(i,j-1);
				if(neigh[i][j]==1){
					cout << "1\n";
					return 0;
				}
			}
		}
	cout << "2\n";
}


#include <iostream>
#include <vector>
using namespace std;
int n,m,s;
int neigh[50][50];
vector<string> grid;
bool lives(int r, int c){
	if(r<0||c<0||r>=n||c>=m)
		return 0;
	return grid[r][c]=='#';
}
void dfs(int r, int c){
	if(!lives(r,c))
		return;
	grid[r][c]='2';
	dfs(r+1,c);
	dfs(r-1,c);
	dfs(r,c+1);
	dfs(r,c-1);
}
void fix_grid(){
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]!='#'&&grid[i][j]!='.')
				grid[i][j]='#';
}
bool can_remove(int r, int c){
	grid[r][c]='3';
	int sr=-1,sc=-1;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			if(lives(i,j)){
				sr=i;
				sc=j;
			}
		}
	if(sr==-1&&sc==-1)
		return false;
	dfs(sr,sc);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				return true;
	return false;
}
int main(){
	cin >> n >> m;
	grid.resize(n);
	for(int i = 0; i < n; ++i)
		cin >> grid[i];
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				s++;
	if(s<=2){
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(lives(i,j))
				if(can_remove(i,j)){
					cout << "1\n";
					return 0;
				}
				else
					fix_grid();
	cout << "2\n";
}


#include <iostream>
#include <vector>
using namespace std;
int n,m,s;
int neigh[50][50];
vector<string> grid;
bool lives(int r, int c){
	if(r<0||c<0||r>=n||c>=m)
		return 0;
	return grid[r][c]=='#';
}
void dfs(int r, int c){
	if(!lives(r,c))
		return;
	grid[r][c]='2';
	dfs(r+1,c);
	dfs(r-1,c);
	dfs(r,c+1);
	dfs(r,c-1);
}
bool can_remove(int r, int c){
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]!='#'&&grid[i][j]!='.')
				grid[i][j]='#';
	grid[r][c]='3';
	int sr,sc;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			if(lives(i,j)){
				sr=i;
				sc=j;
			}
		}
	dfs(sr,sc);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				return false;
	return true;
}
int main(){
	cin >> n >> m;
	grid.resize(n);
	for(int i = 0; i < n; ++i)
		cin >> grid[i];
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				s++;
	if(s<=2){
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(can_remove(i,j)){
				cout << "1\n";
				return 0;
			}
	cout << "2\n";
}


#include <iostream>
#include <vector>
using namespace std;
int n,m,s;
int neigh[50][50];
vector<string> grid;
bool lives(int r, int c){
	if(r<0||c<0||r>=n||c>=m)
		return 0;
	return grid[r][c]=='#';
}
void dfs(int r, int c){
	if(!lives(r,c))
		return;
	grid[r][c]='2';
	dfs(r+1,c);
	dfs(r-1,c);
	dfs(r,c+1);
	dfs(r,c-1);
}
bool can_remove(int r, int c){
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]!='#'&&grid[i][j]!='.')
				grid[i][j]='#';
	grid[r][c]='3';
	int sr,sc;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			if(lives(i,j)){
				sr=i;
				sc=j;
			}
		}
	dfs(sr,sc);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				return true;
	return false;
}
int main(){
	cin >> n >> m;
	grid.resize(n);
	for(int i = 0; i < n; ++i)
		cin >> grid[i];
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				s++;
	if(s<=2){
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(can_remove(i,j)){
				cout << "1\n";
				return 0;
			}
	cout << "2\n";
}


#include <iostream>
#include <vector>
using namespace std;
int n,m,s;
int neigh[50][50];
vector<string> grid;
bool lives(int r, int c){
	if(r<0||c<0||r>=n||c>=m)
		return 0;
	return grid[r][c]=='#';
}
void dfs(int r, int c){
	if(!lives(r,c))
		return;
	grid[r][c]='2';
	dfs(r+1,c);
	dfs(r-1,c);
	dfs(r,c+1);
	dfs(r,c-1);
}
bool can_remove(int r, int c){
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]!='#'&&grid[i][j]!='.')
				grid[i][j]='#';
	grid[r][c]='3';
	int sr=-1,sc=-1;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			if(lives(i,j)){
				sr=i;
				sc=j;
			}
		}
	if(sr==-1&&sc==-1)
		return false;
	dfs(sr,sc);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				return true;
	return false;
}
int main(){
	cin >> n >> m;
	grid.resize(n);
	for(int i = 0; i < n; ++i)
		cin >> grid[i];
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j]=='#')
				s++;
	if(s<=2){
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(lives(i,j))
				if(can_remove(i,j)){
					cout << "1\n";
					return 0;
				}
	cout << "2\n";
}