#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int w,h;
char f[13][65];
int id[13][65];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
queue<T> q;
int id_num;
int par[200];
int sumx[200],num[200];
double lf[200],rg[200];
vector<int> g[200];
bool ans;
void dfs(int x,int y,int idx){
    id[x][y]=idx;
    sumx[idx]+=x;
    num[idx]++;
    for(int i=0;i<4;i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx<0||nx>=w||ny<0||ny>=h)continue;
        if(id[nx][ny]!=-1)continue;
        if(f[nx][ny]==f[x][y])dfs(nx,ny,idx);
        else if(f[nx][ny]!='.'&&i==0)q.push(T(idx,P(nx,ny)));
    }
}
void culc(int idx){
    for(int i=0;i<g[idx].size();i++){
        culc(g[idx][i]);
    }
    for(int i=0;i<g[idx].size();i++){
        int ch = g[idx][i];
        sumx[idx] += sumx[ch];
        num[idx] += num[ch];
    }
    double ave = (double)sumx[idx]/(double)num[idx];
    //printf("%d ave: %lf left: %lf right: %lf\n",idx,ave,lf[idx],rg[idx]);
    if(ave<=lf[idx]||ave>=rg[idx])ans = false;
}
int solve(){
 
    scanf("%d %d",&w,&h);
    if(w+h==0)return 1;
     
    for(int i=h-1;i>=0;i--){
        for(int j=0;j<w;j++){
            scanf(" %c",&f[j][i]);
        }
    }
     
    // initialize
    memset(id,-1,sizeof(id));
    id_num = 0;
    for(int i=0;i<200;i++){
        lf[i]=100.0;
        rg[i]=-1.0;
        sumx[i]=0;
        num[i]=0;
        g[i].clear();
        par[i]=-1;
    }
    ans = true;
    //
     
    int st = -1;
    for(int i=0;i<w;i++){
        if(f[i][0]!='.'){
            st = i;
            lf[0]=min(lf[0],(double)i-0.5);
            rg[0]=max(rg[0],(double)i+0.5);
        }
    }
    dfs(st,0,id_num++);
    while(!q.empty()){
        T a = q.front();
        q.pop();
        int x = a.sec.fi,y = a.sec.sec;
        if(id[x][y]!=-1){
            int idx = id[x][y];
            lf[idx]=min(lf[idx],(double)x-0.5);
            rg[idx]=max(rg[idx],(double)x+0.5);
            continue;
        }
        par[id_num]=a.fi;
        lf[id_num]=min(lf[id_num],(double)x-0.5);
        rg[id_num]=max(rg[id_num],(double)x+0.5);
        g[a.fi].pb(id_num);
        dfs(x,y,id_num++);
    }
     
    //debug
    /*printf("\n");
    for(int i=h-1;i>=0;i--){
        for(int j=0;j<w;j++){
            if(id[j][i]==-1)printf(".");
            else printf("%d",id[j][i]);
        }
        printf("\n");
    }*/
    /*for(int i=0;i<id_num;i++){
        printf("%d par %d left %lf right %lf ")
    }*/
     
    culc(0);
     
    if(ans)printf("STABLE\n");
    else printf("UNSTABLE\n");
     
    return 0;
}
int main(){
    while(!solve()){}
    return 0;
}

Measured memory_bytes: 3072