#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int N, M;
int vis[MAXN][MAXN], ans[MAXN][MAXN], pre1[MAXN][MAXN], pre2[MAXN][MAXN];
int cnt[MAXN * MAXN][3], p = 0;
int Up[MAXN][MAXN];
int Down[MAXN][MAXN];
int Left[MAXN][MAXN];
int Right[MAXN][MAXN];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) {
    Left[i][0] = 0;
    Right[i][M + 1] = M + 1;
    getchar();
    for (int j = 1; j <= M; j++) {
      Up[0][j] = 0;
      Down[N + 1][j] = N + 1;
      char c;
      scanf("%c", &c);
      if (c == '*') vis[i][j] = true;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (vis[i][j])
        Up[i][j] = Up[i - 1][j];
      else
        Up[i][j] = i;
      if (vis[i][j])
        Left[i][j] = Left[i][j - 1];
      else
        Left[i][j] = j;
    }
  }
  for (int i = N; i >= 1; i--) {
    for (int j = M; j >= 1; j--) {
      if (vis[i][j])
        Down[i][j] = Down[i + 1][j];
      else
        Down[i][j] = i;
      if (vis[i][j])
        Right[i][j] = Right[i][j + 1];
      else
        Right[i][j] = j;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (i - 1 < Up[i][j]) continue;
      if (i + 1 > Down[i][j]) continue;
      if (j - 1 < Left[i][j]) continue;
      if (j + 1 > Right[i][j]) continue;
      if (!vis[i][j]) continue;
      int sz = min(i - Up[i][j] - 1,
                   min(Down[i][j] - i - 1,
                       min(j - Left[i][j] - 1, Right[i][j] - j - 1)));
      if (!sz) continue;
      pre1[i][j - sz] += 1;
      pre2[i - sz][j] += 1;
      pre1[i][j + sz + 1] -= 1;
      pre2[i + sz + 1][j] -= 1;
      cnt[++p][0] = i;
      cnt[p][1] = j;
      cnt[p][2] = sz;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      pre1[i][j] += pre1[i][j - 1];
    }
  }
  for (int j = 1; j <= M; j++) {
    for (int i = 1; i <= N; i++) {
      pre2[i][j] += pre2[i - 1][j];
      ans[i][j] = pre1[i][j] || pre2[i][j];
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (vis[i][j] ^ ans[i][j]) {
        printf("-1\n");
        return 0;
      }
    }
  }
  printf("%d\n", p);
  for (int i = 1; i <= p; i++) {
    printf("%d %d %d\n", cnt[i][0], cnt[i][1], cnt[i][2]);
  }
  return 0;
}
