#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const long long MOD = 1000000007;
int dX[] = {0, 0, 1, -1};
int dY[] = {1, -1, 0, 0};
struct out {
  int x, y, len;
};
char F[N][N], G[N][N];
int n, m, cur, cnt[4][N][N], par[4][N][N];
vector<out> v;
int Find(int x, int y, int d) {
  if (par[d][x][y] == y && d < 2) return y;
  if (par[d][x][y] == x && d >= 2) return x;
  if (d < 2)
    return par[d][x][y] = Find(x, par[d][x][y], d);
  else
    return par[d][x][y] = Find(par[d][x][y], y, d);
}
void Try(int x, int y) {
  int mn = 2000000100;
  for (int i = 0; i < 4; ++i) mn = min(mn, cnt[i][x][y] - 1);
  if (mn <= 0) return;
  v.push_back({x, y, mn});
  int c = y, d;
  d = 0;
  while (c - y <= mn && c <= m) {
    int P = Find(x, c + 1, d);
    par[d][x][c] = Find(x, c + 1, d);
    F[x][c] = '*';
    c = P;
  }
  d = 1;
  c = y;
  while (y - c <= mn && c) {
    int P = Find(x, c - 1, d);
    par[d][x][c] = P;
    F[x][c] = '*';
    c = P;
  }
  d = 2;
  c = x;
  while (c - x <= mn && c <= n) {
    int P = Find(c + 1, y, d);
    par[d][c][y] = P;
    F[c][y] = '*';
    c = P;
  }
  d = 3;
  c = x;
  while (x - c <= mn && c) {
    int P = Find(c - 1, y, d);
    par[d][c][y] = P;
    F[c][y] = '*';
    c = P;
  }
}
bool Equal() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (G[i][j] != F[i][j]) return 0;
  return 1;
}
void Print() {
  for (int i = 1; i <= n; ++i) {
    printf("\n");
    for (int j = 1; j <= m; ++j) printf("%c", F[i][j]);
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; ++i) scanf("%s", G[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) F[i][j] = '.';
  for (int d = 0; d < 2; ++d)
    for (int i = 1; i <= n + 2; ++i)
      for (int j = 1; j <= m + 2; ++j) par[d][i][j] = j;
  for (int d = 2; d < 4; ++d)
    for (int i = 1; i <= m + 2; ++i)
      for (int j = 1; j <= n + 2; ++j) par[d][j][i] = j;
  for (int i = 1; i <= n; ++i) {
    cur = 0;
    for (int j = 1; j <= m; ++j)
      (G[i][j] == '*' ? cur += 1 : cur = 0), cnt[0][i][j] = cur;
  }
  for (int i = 1; i <= m; ++i) {
    cur = 0;
    for (int j = 1; j <= n; ++j)
      (G[j][i] == '*' ? cur += 1 : cur = 0), cnt[1][j][i] = cur;
  }
  for (int i = 1; i <= m; ++i) {
    cur = 0;
    for (int j = n; j; --j)
      (G[j][i] == '*' ? cur += 1 : cur = 0), cnt[2][j][i] = cur;
  }
  for (int i = 1; i <= n; ++i) {
    cur = 0;
    for (int j = m; j; --j)
      (G[i][j] == '*' ? cur += 1 : cur = 0), cnt[3][i][j] = cur;
  }
  for (int i = 2; i < n; ++i)
    for (int j = 2; j < m; ++j)
      if (G[i][j] == '*') Try(i, j);
  if (Equal()) {
    printf("%d\n", (v.size()));
    for (int i = 0; i < (v.size()); ++i)
      printf("%d %d %d\n", v[i].x, v[i].y, v[i].len);
  } else
    puts("-1");
  return 0;
}
