#include <bits/stdc++.h>
using namespace std;
ifstream f("1.in");
int n, m, up[1005][1005], down[1005][1005], lf[1005][1005], rg[1005][1005],
    UP[1005][1005], LEFT[1005][1005];
char a[1005][1005], b[1005][1005];
vector<pair<pair<int, int>, int> > ans;
int val;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &a[i][j]);
      b[i][j] = '.';
    }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++)
      if (a[i][j] == '*') up[i][j] = up[i - 1][j] + 1;
    for (int i = n; i >= 1; i--)
      if (a[i][j] == '*') down[i][j] = down[i + 1][j] + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '*') lf[i][j] = lf[i][j - 1] + 1;
    for (int j = m; j >= 1; j--)
      if (a[i][j] == '*') rg[i][j] = rg[i][j + 1] + 1;
  }
  int xup, xdown, yleft, yright;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '*') {
        val = min({lf[i][j], down[i][j], rg[i][j], up[i][j]});
        if (val != 1) {
          b[i][j] = '*';
          val--;
          ans.push_back({{i, j}, val});
          b[i][j] = '*';
          xup = i - val;
          xdown = i + val;
          yleft = j - val;
          yright = j + val;
          UP[xup][j]++;
          UP[xdown + 1][j]--;
          LEFT[i][yleft]++;
          LEFT[i][yright + 1]--;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      UP[i][j] += UP[i - 1][j];
      LEFT[i][j] += LEFT[i][j - 1];
      if (UP[i][j] != 0 || LEFT[i][j] != 0) b[i][j] = '*';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (b[i][j] != a[i][j]) {
        cout << -1;
        return 0;
      }
  }
  cout << ans.size() << endl;
  for (auto it : ans)
    printf("%d %d %d\n", it.first.first, it.first.second, it.second);
  return 0;
}
