#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
int n, m;
char mat[N][N];
int L[N][N], R[N][N], U[N][N], D[N][N];
int sL[N][N], sR[N][N], sU[N][N], sD[N][N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf(" %s", mat[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      L[i][j] = -1;
      U[i][j] = -1;
      R[i][j] = m;
      D[i][j] = n;
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j + 1 < m; j++) {
      if (mat[i][j] == '.')
        L[i][j + 1] = j;
      else
        L[i][j + 1] = L[i][j];
    }
    for (int j = m - 1; j > 0; j--) {
      if (mat[i][j] == '.')
        R[i][j - 1] = j;
      else
        R[i][j - 1] = R[i][j];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (mat[i][j] == '.')
        U[i + 1][j] = i;
      else
        U[i + 1][j] = U[i][j];
    }
    for (int i = n - 1; i > 0; i--) {
      if (mat[i][j] == '.')
        D[i - 1][j] = i;
      else
        D[i - 1][j] = D[i][j];
    }
  }
  vector<tuple<int, int, int>> ans;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '.') continue;
      int t = min(R[i][j] - j, j - L[i][j]);
      t = min(t, min(D[i][j] - i, i - U[i][j]));
      t--;
      if (t == 0) continue;
      ans.emplace_back(i, j, t);
      sL[i][j] = sR[i][j] = sD[i][j] = sU[i][j] = t + 1;
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j + 1 < m; j++) {
      sL[i][j + 1] = max(sL[i][j + 1], sL[i][j] - 1);
    }
    for (int j = m - 1; j > 0; j--) {
      sR[i][j - 1] = max(sR[i][j - 1], sR[i][j] - 1);
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i + 1 < n; i++) {
      sU[i + 1][j] = max(sU[i + 1][j], sU[i][j] - 1);
    }
    for (int i = n - 1; i > 0; i--) {
      sD[i - 1][j] = max(sD[i - 1][j], sD[i][j] - 1);
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int t = 0;
      t += sU[i][j];
      t += sL[i][j];
      t += sD[i][j];
      t += sR[i][j];
      if ((mat[i][j] == '.') != (t == 0)) {
        return printf("-1\n"), 0;
      }
    }
  printf("%d\n", (int)ans.size());
  int a, b, c;
  for (auto x : ans) {
    tie(a, b, c) = x;
    printf("%d %d %d\n", a + 1, b + 1, c);
  }
}
