#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, i, j, k;
  cin >> n >> m;
  char s[n][m];
  long long l[n][m], r[n][m], up[n][m], down[n][m], h[n][m], v[n][m];
  bool state = 1;
  memset(l, 0, sizeof l);
  memset(r, 0, sizeof r);
  memset(up, 0, sizeof up);
  memset(down, 0, sizeof down);
  memset(h, 0, sizeof h);
  memset(v, 0, sizeof v);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> s[i][j];
      if (s[i][j] == '*') {
        l[i][j] = r[i][j] = up[i][j] = down[i][j] = 1;
      }
    }
  }
  for (i = 1; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '*') up[i][j] += up[i - 1][j];
    }
  }
  for (i = n - 2; i >= 0; i--) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '*') down[i][j] += down[i + 1][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 1; j < m; j++) {
      if (s[i][j] == '*') l[i][j] += l[i][j - 1];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = m - 2; j >= 0; j--) {
      if (s[i][j] == '*') r[i][j] += r[i][j + 1];
    }
  }
  vector<pair<long long, pair<long long, long long> > > ans;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      long long sizes =
          min(l[i][j], min(r[i][j], min(up[i][j], down[i][j]))) - 1;
      if (sizes > 0) {
        if (j - sizes >= 0) h[i][j - sizes] += 1;
        if (j + sizes + 1 < m) h[i][j + sizes + 1] -= 1;
        if (i - sizes >= 0) v[i - sizes][j] += 1;
        if (i + sizes + 1 < n) v[i + sizes + 1][j] -= 1;
        ans.push_back({sizes, {i + 1, j + 1}});
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (i - 1 >= 0) v[i][j] += v[i - 1][j];
      if (j - 1 >= 0) h[i][j] += h[i][j - 1];
      if (h[i][j] <= 0 && v[i][j] <= 0 && s[i][j] == '*') {
        state = 0;
      }
    }
  }
  if (!state) {
    cout << -1;
    return 0;
  }
  cout << ans.size() << endl;
  for (auto x : ans) {
    cout << x.second.first << " " << x.second.second << " " << x.first << endl;
  }
  return 0;
}
