#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1005;
using namespace std;
char s[maxn][maxn], s2[maxn][maxn];
int l[maxn][maxn], r[maxn][maxn], u[maxn][maxn], d[maxn][maxn];
int len[maxn][maxn], W[maxn][maxn], S[maxn][maxn];
struct node {
  int x, y, s;
  node() {}
  node(int tx, int ty, int ts) { x = tx, y = ty, s = ts; }
} f[maxn * maxn];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf(" %s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '*') l[i][j] = l[i][j - 1] + 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      if (s[i][j] == '*') r[i][j] = r[i][j + 1] + 1;
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      if (s[i][j] == '*') u[i][j] = u[i - 1][j] + 1;
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = n; i >= 1; i--) {
      if (s[i][j] == '*') d[i][j] = d[i + 1][j] + 1;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '*') {
        len[i][j] = min(l[i][j], min(r[i][j], min(u[i][j], d[i][j])));
        len[i][j]--;
        if (!len[i][j]) continue;
        int t = len[i][j];
        f[++cnt] = node(i, j, len[i][j]);
        W[i][j - t]++, W[i][j + t + 1]--;
        S[i - t][j]++, S[i + t + 1][j]--;
      }
    }
  }
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      W[i][j] += W[i][j - 1], S[i][j] += S[i - 1][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '*' && !W[i][j] && !S[i][j]) flag = false;
    }
  }
  if (!flag)
    puts("-1");
  else {
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) {
      printf("%d %d %d\n", f[i].x, f[i].y, f[i].s);
    }
  }
  return 0;
}
