#include <bits/stdc++.h>
using namespace std;
struct star {
  int x, y, w;
};
struct maxW {
  int l, r, u, d;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  vector<vector<int>> pref(n + 1, vector<int>(m + 1));
  vector<vector<maxW>> dirs(n, vector<maxW>(m));
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (in[i][j] != '*') continue;
      if (in[i - 1][j] == '*') dirs[i][j].u = dirs[i - 1][j].u + 1;
      if (in[i][j - 1] == '*') dirs[i][j].l = dirs[i][j - 1].l + 1;
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      if (in[i][j] != '*') continue;
      if (in[i + 1][j] == '*') dirs[i][j].d = dirs[i + 1][j].d + 1;
      if (in[i][j + 1] == '*') dirs[i][j].r = dirs[i][j + 1].r + 1;
    }
  }
  vector<star> res;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (in[i][j] != '*') continue;
      maxW d = dirs[i][j];
      int w = min({d.l, d.r, d.u, d.d});
      if (w > 0) {
        pref[i - w][j] += 1;
        pref[i - w][j + 1] += -1;
        pref[i + w + 1][j] += -1;
        pref[i + w + 1][j + 1] += 1;
        pref[i][j - w] += 1;
        pref[i + 1][j - w] += -1;
        pref[i][j + w + 1] += -1;
        pref[i + 1][j + w + 1] += 1;
        res.push_back({j, i, w});
      }
    }
  }
  bool ok = true;
  for (int i = 1; i <= n; i++) {
    pref[i][0] += pref[i - 1][0];
  }
  for (int j = 1; j <= m; j++) {
    pref[0][j] += pref[0][j - 1];
  }
  for (int i = 1; i <= n && ok; i++) {
    for (int j = 1; j <= m && ok; j++) {
      pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
      ok &= (pref[i - 1][j - 1] > 0) == (in[i - 1][j - 1] == '*');
    }
  }
  if (ok) {
    cout << res.size() << "\n";
    for (star x : res) {
      cout << (x.y + 1) << " " << (x.x + 1) << " " << x.w << "\n";
    }
  } else {
    cout << "-1\n";
  }
}
