#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 7;
char s[maxn][maxn];
int n, m;
int l[maxn][maxn], r[maxn][maxn], up[maxn][maxn], down[maxn][maxn],
    sum[maxn][maxn];
int W[maxn][maxn], S[maxn][maxn];
struct Node {
  int x, y, s;
  Node() {}
  Node(int _x, int _y, int _s) {
    x = _x;
    y = _y;
    s = _s;
  }
} f[maxn * maxn];
int main() {
  int k = 0;
  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 i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      if (s[j][i] == '*') up[j][i] = up[j - 1][i] + 1;
  for (int i = 1; i <= m; i++)
    for (int j = n; j >= 1; j--)
      if (s[j][i] == '*') down[j][i] = down[j + 1][i] + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] == '*') {
        sum[i][j] = min(l[i][j], min(r[i][j], min(up[i][j], down[i][j])));
        sum[i][j]--;
        if (sum[i][j] == 0) continue;
        int v = sum[i][j];
        f[++k] = Node(i, j, sum[i][j]);
        W[i][j - v]++;
        W[i][j + v + 1]--;
        S[i - v][j]++;
        S[i + v + 1][j]--;
      }
  int flag = 0;
  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 = 1;
  if (flag == 1)
    printf("-1\n");
  else {
    printf("%d\n", k);
    for (int i = 1; i <= k; i++) printf("%d %d %d\n", f[i].x, f[i].y, f[i].s);
  }
}
