#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
string s[66],t[66];
int dy[]={-1,0,0,1};
int dx[]={0,1,-1,0};
int h,cnt,w,used[66][130],sum;
map<int,int>id_sum;
map<int,vector<int> >id_each;
void id_dfs(int y,int x,vector<vector<int> >&a,char X,vector<int>&id_x){
  a[y][x]=cnt;
  id_x.push_back(x);
  used[y][x]=1;
  sum++;
  r(i,4){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(ny<0||nx<0||ny>=h||nx>=w)continue;
    if(used[ny][nx])continue;
    if(s[ny][nx]==X)id_dfs(ny,nx,a,X,id_x);
  }
}
P get_lr(int y,int x,vector<vector<int> >&a){
  int id=a[y][x];
  int ny=y;
  int l_x=1e8,r_x=-1e8;
  for(;ny<h;ny++){
    int flag=0;
    r(j,w)if(a[ny][j]==id){
      if(ny+1==h||(a[ny+1][j]!=-1&&a[ny+1][j]!=id)){
        l_x=min(l_x,j);
        r_x=max(r_x,j);
      }
      flag++;
    }
    if(!flag)break;
  }
  return P(l_x,r_x);
}
vector<int> get_data(int y,int x,vector<vector<int> >&a){
  int used2[600]={};
  int oy=y,ox=x;
  vector<int>id_x;
  queue<P>q;
  q.push(P(y,x));
  used2[a[y][x]]=1;
  while(!q.empty()){
    P p=q.front();q.pop();
    y=p.first;
    x=p.second;
    r(i,h)r(j,w)if(a[i][j]==a[y][x]){
      if(a[i][j]==a[oy][ox])used[i][j]=1;
      id_x.push_back(j);
      r(k,1){
        int ny=i+dy[k];
        int nx=j+dx[k];
        if(ny<0||nx<0||ny>=h||nx>=w)continue;
        if(a[ny][nx]==-1)continue;
        if(used2[a[ny][nx]])continue;
        used2[a[ny][nx]]=1;
        q.push(P(ny,nx));
      }
    }
  }
  return id_x;
}
signed main(){
  while(cin>>w>>h,w){
    id_sum.clear();
    id_each.clear();
    cnt=0;
    memset(used,0,sizeof(used));
    r(i,h)cin>>s[i];
    vector<vector<int> >a(h,vector<int>(w));
    r(i,h)r(j,w)a[i][j]=-1;
    r(i,h)r(j,w)if(isdigit(s[i][j])){
      if(!used[i][j]){
        vector<int>id_x;
        sum=0;
        id_dfs(i,j,a,s[i][j],id_x);
        id_sum[cnt]=sum;
        id_each[cnt++]=id_x;
      }
    }
    int flag=0;
    memset(used,0,sizeof(used));
    r(i,h)r(j,w)if(isdigit(s[i][j])){
      if(used[i][j])continue;
      P x_lr=get_lr(i,j,a);
      vector<int>v=get_data(i,j,a);
      double X=0,L=x_lr.first,R=x_lr.second;
      r(i,v.size())X+=v[i];
      X/=(double)v.size();
      if(!(L-0.5<X&&X<R+0.5))flag++;
    }
    if(!flag)cout<<"STABLE"<<endl;
    else cout<<"UNSTABLE"<<endl;
  }
}
