#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1168&lang=jp
typedef pair<int, int> pii;
typedef pair<int, double> pid;
const int INF = 1e9;
const double eps = 1e-9;
struct piece {
	int idx;
	int xl, xr;
	vector<pii> loc;
	double g;
	vector<int> next_piece;
	piece(): loc(4),idx(0),g(0.0),xl(-INF),xr(INF) {}
	void add_next(int nextidx) { this->next_piece.push_back(nextidx); }
	void init_loc(int x, int y) {
		loc[idx++] = { y,x };
		if (idx == 4) this->calc_gx();
	}
	void calc_gx() {
		for (int i = 0; i < 4;i++) {
			g += (0.5 + (double)loc[i].second);
		}
		g /= 4.0;
	}
	void calc_xlr(int x) {
		if (xl == -INF) {
			xl = x; xr = x + 1;
		}
		else {
			xl = min(xl, x); xr = max(xr, x + 1);
		}
	}
};

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

void calc_piece(int x, int y,int idx,vector<piece>& p, vector<vector<char>>&m, vector<vector<int>>& used) {
	used[y][x] = idx;
	if (idx == (int)p.size()) {
		p.push_back(piece());
	}
	p[idx].init_loc(x, y);
	for (int i = 0; i < 4;i++) {
		int ny = y + dy[i], nx = x + dx[i];
		if (m[ny][nx] == '#' || m[ny][nx] == '.')continue;
		if (used[ny][nx] != -1 && i == 1) {
			if (used[ny][nx] != idx)p[used[ny][nx]].calc_xlr(x);
		}
		if (used[ny][nx] != -1)continue;
		if (m[ny][nx] == m[y][x]) {
			calc_piece(nx, ny, idx, p, m, used);
		}
		else if (i == 1) {
			p[idx].add_next((int)p.size());
			calc_piece(nx, ny, (int)p.size(), p, m, used);
			p[used[ny][nx]].calc_xlr(x);
		}
	}
}

/* return { mass , center of gravity }*/
pid solve(int idx, vector<piece>& p) {
	int m = 4;
	double g = p[idx].g;
	double mg = m*g;
	for (int next : p[idx].next_piece) {
		auto up = solve(next, p);
		if (up.second > INF) {
			return make_pair(1, (double)(INF + 1.0));
		}
		m += up.first;
		mg += up.first * up.second;
	}
	double ret_g = mg / (double)m;

	if (ret_g - p[idx].xl > 0 && p[idx].xr - ret_g > 0) {
		return make_pair(m, ret_g);
	}
	else {
		return make_pair(1, (double)(INF + 1.0));
	}
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	int w, h;
	while (cin >> w >> h, w | h) {
		vector<piece> p;
		vector<vector<char>> m(h + 2, vector<char>(w + 2, '#'));
		vector<vector<int>> used(h + 2, vector<int>(w + 2, -1));
		for (int i = h; i >= 1; i--)for (int j = 1; j <= w;j++)cin >> m[i][j];
		for (int i = 1; i <= w;i++) {
			if (m[1][i] == '.')continue;
			if (used[1][i] != -1) {
				p[0].calc_xlr(i);
				continue;
			}
			calc_piece(i, 1, (int)p.size(), p, m, used);
			p[0].calc_xlr(i);
		}
		
		auto Ans = solve(0, p);
		if (Ans.second > INF) {
			cout << "UNSTABLE" << endl;
		}
		else {
			cout << "STABLE" << endl;
		}
		
	}
	return 0;
}