#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x, y, len;
};
vector<edge> res;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  edge get;
  int n, m, i, j, fl = 1;
  int left, right, up, down, minn;
  string s;
  cin >> n >> m;
  int line[n + 5][m + 5];
  int uline[n + 5][m + 5];
  int dp[n + 5][m + 5];
  int pref[n + 5][m + 5];
  int suff[n + 5][m + 5];
  int upref[n + 5][m + 5];
  int usuff[n + 5][m + 5];
  memset(pref, 0, sizeof(pref));
  memset(suff, 0, sizeof(suff));
  memset(upref, 0, sizeof(upref));
  memset(usuff, 0, sizeof(usuff));
  memset(line, 0, sizeof(line));
  memset(uline, 0, sizeof(uline));
  for (i = 1; i <= n; i++) {
    cin >> s;
    for (j = 1; j <= m; j++) {
      if (s[j - 1] == '.')
        dp[i][j] = 0;
      else
        dp[i][j] = 1;
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (dp[i][j] == 1) pref[i][j] = 1 + pref[i][j - 1];
  for (i = 1; i <= n; i++)
    for (j = m; j >= 1; j--)
      if (dp[i][j] == 1) suff[i][j] = 1 + suff[i][j + 1];
  for (j = 1; j <= m; j++)
    for (i = 1; i <= n; i++)
      if (dp[i][j] == 1) upref[i][j] = 1 + upref[i - 1][j];
  for (j = 1; j <= m; j++)
    for (i = n; i >= 1; i--)
      if (dp[i][j] == 1) usuff[i][j] = 1 + usuff[i + 1][j];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (dp[i][j] == 1) {
        left = pref[i][j] - 1;
        right = suff[i][j] - 1;
        up = upref[i][j] - 1;
        down = usuff[i][j] - 1;
        minn = min({left, right, up, down});
        if (minn >= 1) {
          get.x = i;
          get.y = j;
          get.len = minn;
          res.push_back(get);
          line[i][j - minn]++;
          line[i][j + minn + 1]--;
          uline[i - minn][j]++;
          uline[i + minn + 1][j]--;
        }
      }
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) line[i][j] += line[i][j - 1];
  for (j = 1; j <= m; j++)
    for (i = 1; i <= n; i++) uline[i][j] += uline[i - 1][j];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (dp[i][j] == 1) {
        if (line[i][j] == 0 && uline[i][j] == 0) {
          fl = 0;
          break;
        }
      }
    }
    if (fl == 0) break;
  }
  if (fl == 0)
    cout << -1 << endl;
  else {
    cout << res.size() << endl;
    for (auto e : res) cout << e.x << " " << e.y << " " << e.len << endl;
  }
  return 0;
}
