#include <bits/stdc++.h>
using namespace std;
int M[1002][1002];
int A[1002][1002];
int U[1002][1002];
int L[1002][1002];
int D[1002][1002];
int R[1002][1002];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      if (c == '*') M[i][j] = 1;
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      L[i][j] = (L[i][j - 1] + 1) * M[i][j];
      U[i][j] = (U[i - 1][j] + 1) * M[i][j];
      R[i][m - j + 1] = (R[i][m - j + 2] + 1) * M[i][m - j + 1];
      D[n - i + 1][j] = (D[n - i + 2][j] + 1) * M[n - i + 1][j];
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      A[i][j] = min(min(L[i][j], R[i][j]), min(U[i][j], D[i][j]));
      if (A[i][j] == 1) A[i][j] = 0;
    }
  for (int i = 1; i <= n; ++i) {
    int cur = 0;
    for (int j = 1; j <= m; ++j) {
      cur = max(cur - 1, A[i][j]);
      if (cur) M[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int cur = 0;
    for (int j = m; j > 0; --j) {
      cur = max(cur - 1, A[i][j]);
      if (cur) M[i][j] = 0;
    }
  }
  for (int j = 1; j <= m; ++j) {
    int cur = 0;
    for (int i = 1; i <= n; ++i) {
      cur = max(cur - 1, A[i][j]);
      if (cur) M[i][j] = 0;
    }
  }
  for (int j = 1; j <= m; ++j) {
    int cur = 0;
    for (int i = n; i > 0; --i) {
      cur = max(cur - 1, A[i][j]);
      if (cur) M[i][j] = 0;
    }
  }
  int K = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if (A[i][j]) ++K;
      if (M[i][j]) return cout << -1 << endl, 0;
    }
  cout << K << '\n';
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (A[i][j]) cout << i << ' ' << j << ' ' << A[i][j] - 1 << '\n';
  return 0;
}
