#include <bits/stdc++.h>
using namespace std;
int n, m, a[1005][1005], up[1005][1005], down[1005][1005], lf[1005][1005],
    rt[1005][1005], tt;
char ch[1005][1005];
int T1[1005][1005 << 2], T2[1005][1005 << 2], mk1[1005][1005 << 2],
    mk2[1005][1005 << 2];
struct node {
  int x, y, z;
} ans[1005 * 1005];
void pushdown(int ty, int k) {
  mk1[ty][k << 1] += mk1[ty][k], mk1[ty][k << 1 | 1] += mk1[ty][k];
  T1[ty][k << 1] += mk1[ty][k], T1[ty][k << 1 | 1] = mk1[ty][k];
  mk1[ty][k] = 0;
}
void pushdown2(int ty, int k) {
  mk2[ty][k << 1] += mk2[ty][k], mk2[ty][k << 1 | 1] += mk2[ty][k];
  T2[ty][k << 1] += mk2[ty][k], T2[ty][k << 1 | 1] = mk2[ty][k];
  mk2[ty][k] = 0;
}
void update(int l, int r, int a, int b, int k, int ty, int ad) {
  if (a <= l && r <= b) return (void)(T1[ty][k] += ad, mk1[ty][k] += ad);
  int mid = (l + r) >> 1;
  if (mk1[ty][k]) pushdown(ty, k);
  if (a <= mid) update(l, mid, a, b, k << 1, ty, ad);
  if (b > mid) update(mid + 1, r, a, b, k << 1 | 1, ty, ad);
  T1[ty][k] = min(T1[ty][k << 1], T1[ty][k << 1 | 1]);
}
void update2(int l, int r, int a, int b, int k, int ty, int ad) {
  if (a <= l && r <= b) return (void)(T2[ty][k] += ad, mk2[ty][k] += ad);
  int mid = (l + r) >> 1;
  if (mk2[ty][k]) pushdown2(ty, k);
  if (a <= mid) update2(l, mid, a, b, k << 1, ty, ad);
  if (b > mid) update2(mid + 1, r, a, b, k << 1 | 1, ty, ad);
  T2[ty][k] = min(T2[ty][k << 1], T2[ty][k << 1 | 1]);
}
int que1(int l, int r, int a, int k, int ty) {
  if (l == r) return T1[ty][k];
  int mid = (l + r) >> 1;
  if (mk1[ty][k]) pushdown(ty, k);
  if (a <= mid)
    return que1(l, mid, a, k << 1, ty);
  else
    return que1(mid + 1, r, a, k << 1 | 1, ty);
}
int que2(int l, int r, int a, int k, int ty) {
  if (l == r) return T2[ty][k];
  int mid = (l + r) >> 1;
  if (mk2[ty][k]) pushdown2(ty, k);
  if (a <= mid)
    return que2(l, mid, a, k << 1, ty);
  else
    return que2(mid + 1, r, a, k << 1 | 1, ty);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch[i] + 1);
    for (int j = 1; j <= m; j++)
      if (ch[i][j] == '*') a[i][j] = 1;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      if (a[j][i])
        up[j][i] = up[j - 1][i] + 1;
      else
        up[j][i] = 0;
    for (int j = n; j >= 1; j--)
      if (a[j][i])
        down[j][i] = down[j + 1][i] + 1;
      else
        down[j][i] = 0;
  }
  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;
      else
        lf[i][j] = 0;
    for (int j = m; j >= 1; j--)
      if (a[i][j])
        rt[i][j] = rt[i][j + 1] + 1;
      else
        rt[i][j] = 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j]) update(1, n, i, i, 1, j, -1), update2(1, m, j, j, 1, i, -1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j]) {
        int tmp = min(min(up[i][j], down[i][j]), min(lf[i][j], rt[i][j])) - 1;
        if (!tmp) continue;
        ans[++tt] = (node){i, j, tmp};
        update(1, n, i - tmp, i + tmp, 1, j, 1);
        update2(1, m, j - tmp, j + tmp, 1, i, 1);
      }
  }
  bool fd = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (que1(1, n, i, 1, j) + que2(1, m, j, 1, i) < -1) fd = 0;
  if (!fd)
    puts("-1");
  else {
    printf("%d\n", tt);
    for (int i = 1; i <= tt; i++)
      printf("%d %d %d\n", ans[i].x, ans[i].y, ans[i].z);
  }
}
