#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct Block {
  Block() : xl(0), xr(0), cnt(12), n(0), ng(0) {
    fill(cnt.begin(), cnt.end(), 0);
  }

  int xl, xr;
  vector<int> cnt;
  vector<Block> children;

  int n, ng;
};

void makeTree(Block &b, int y, int x, char n,
	      vector<vector<char> > &q, int ly, int lx) {
  if (q[y][x] == '.') {
    return;
  }

  if (q[y][x] > '9') {
    if (q[y][x] - 9 != n && ly == y + 1) {
      b.xl = min(b.xl, lx);
      b.xr = max(b.xr, lx);
    }
    return;
  }

  if (q[y][x] != n) {
    if (ly == y + 1) {
      b.xl = min(b.xl, lx);
      b.xr = max(b.xr, lx);
    }
    if (ly == y - 1) {
      Block child;
      child.xl = child.xr = lx;
      makeTree(child, y, x, q[y][x], q, y, x);
      b.children.push_back(child);
    }
    return;
  }

  b.cnt[x]++;
  q[y][x] += 9;
  makeTree(b, y, x - 1, n, q, y, x);
  makeTree(b, y, x + 1, n, q, y, x);
  makeTree(b, y - 1, x, n, q, y, x);
  makeTree(b, y + 1, x, n, q, y, x);
}

bool stable(Block &b) {
  bool s = true;

  for (int x = 1; x <= 10; x++) {
    b.n += b.cnt[x];
    b.ng += x * b.cnt[x];
  }

  for (int i = 0; i < b.children.size(); i++) {
    s = s && stable(b.children[i]);
    b.n += b.children[i].n;
    b.ng += b.children[i].ng;
  }

  double gVal = (double)b.ng / b.n - 0.5;

  return s && gVal > (b.xl - 1) && gVal < b.xr;
}

int main() {
  int w, h;

  while (cin >> w >> h, w != 0) {
    vector<vector<char> > q(h + 2);
    for (int i = 0; i < h + 2; i++) {
      q[i].resize(w + 2);
      fill(q[i].begin(), q[i].end(), '.');
    }

    for (int y = 1; y <= h; y++) {
      for (int x = 1; x <= w; x++) {
        cin >> q[h - y + 1][x];
      }
    }

    Block root;
    for (int x = w; x >= 1; x--) {
      if (q[1][x] != '.') {
        root.xr = x;
        break;
      }
    }

    for (int x = 1; x <= w; x++) {
      if (q[1][x] != '.') {
        root.xl = x;
        makeTree(root, 1, x, q[1][x], q, 1, x);
        break;
      }
    }

    cout << (stable(root) ? "STABLE" : "UNSTABLE") << endl;
  }

  return 0;
}