#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
  int to, cost;
  bool operator < (const edge& e) const { return cost < e.cost; }
  bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }

typedef pair<int,double> block;
int main()
{
	int w,h;
	while(cin>>w>>h,w)
	{
		vector<string> fld(h);
		REP(i,h) cin>>fld[i];
		auto copy = fld;
		vector<block> blocks;
		vector<vi> data(h,vi(w));
		REP(i,h)REP(j,w) data[i][j] = -1;
		map<int,P> m;
		REP(i,h)REP(j,w)
		{
				if(isdigit(fld[i][j]))
				{
					char c = fld[i][j];
					vector<P> v;
					v.push_back(P(i,j));
					fld[i][j] = '.';
					data[i][j] = blocks.size();
					queue<P> que;
					que.push(P(i,j));
					while(que.size())
					{
						P tmp = que.front();
						que.pop();
						int x = tmp.first;
						int y = tmp.second;
						fld[x][y] = '.';
						data[x][y] = blocks.size();
						REP(i,4)
						{
							int nx = x+dx[i];
							int ny = y+dy[i];
							if(valid(nx,ny,h,w)&&fld[nx][ny]==c) {
								que.push(P(nx,ny));
								v.push_back(P(nx,ny));
							}
						}
					}
					double sum = 0;
					int lx = INF;int rx = -INF;
					REP(i,4)
					{
						sum += v[i].second+0.5;
//						cout << blocks.size() << ": (" << v[i].first << "," << v[i].second << ")" <<endl;
						if(v[i].first==h-1||(
						copy[v[i].first + 1][v[i].second] != '.'&&
						copy[v[i].first + 1][v[i].second] != copy[v[i].first][v[i].second]))
						{
							lx = min(lx,v[i].second);
							rx = max(rx,v[i].second);
						}
					}
					rx++;
					m[blocks.size()] = P(lx,rx);
					sum/=4;
					blocks.push_back(make_pair(4,sum));				
				}
		}
		vector<vector<edge>> g(blocks.size());
		for(int i = 0;i<h-1;i++)
		{
			REP(j,w)
			{
				if(data[i][j] != -1 &&data[i+1][j] !=-1&&data[i][j] != data[i+1][j])
				{
					if(g[data[i][j]].size()>0) continue;
					g[data[i][j]].push_back(edge{data[i+1][j],1});
				}
			}
		}
		bool f = true;
		REP(i,blocks.size())
		{
//			cout << m[i].first << " < " << blocks[i].second << " < " << m[i].second << endl; 
/*        cout << i << ":";
        for (auto k : g[i]) {
          cout << k.to << ";";
        }
        cout << endl;*/
			if(blocks[i].second > m[i].first && blocks[i].second < m[i].second)
			{
				if (g[i].empty()) { continue; }
				else {
					int under = g[i][0].to;
          double MX = blocks[i].first * blocks[i].second,
                 mx = blocks[under].first * blocks[under].second;
          int Mplusm = blocks[i].first + blocks[under].first;
					blocks[under].second = (MX+mx)/Mplusm;
					blocks[under].first += blocks[i].first;
//          cout << "updated: (" << blocks[under].first << "," << blocks[under].second << ")" <<endl;
				}
			}
			else f = false;
		}
		puts(f?"STABLE":"UNSTABLE");
	}
}

Measured memory_bytes: 1224