#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
long long n, m;
char a[N][N];
long long L[N][N] = {0}, R[N][N] = {0}, U[N][N] = {0}, D[N][N] = {0};
long long V[N][N], H[N][N], C[N][N] = {0};
struct node {
  long long x, y, l;
};
void calcU() {
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++)
      if (a[i][j] == '*') U[i][j] = U[i - 1][j] + 1;
}
void calcD() {
  for (int j = 1; j <= m; j++)
    for (int i = n; i >= 1; i--)
      if (a[i][j] == '*') D[i][j] = D[i + 1][j] + 1;
}
void calcL() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '*') L[i][j] = L[i][j - 1] + 1;
}
void calcR() {
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      if (a[i][j] == '*') R[i][j] = R[i][j + 1] + 1;
}
void check() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      H[i][j] += H[i][j - 1];
      if (H[i][j] > 0) C[i][j] = 1;
    }
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++) {
      V[i][j] += V[i - 1][j];
      if (V[i][j] > 0) C[i][j] = 1;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '*' && C[i][j] == 0) {
        cout << -1;
        exit(0);
      }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  calcU();
  calcD();
  calcL();
  calcR();
  vector<node> ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      long long h, v, c;
      v = min(U[i][j], D[i][j]);
      h = min(L[i][j], R[i][j]);
      c = min(v, h) - 1;
      if (c < 1) continue;
      V[i - c][j] += 1;
      H[i][j - c] += 1;
      V[i + c + 1][j] -= 1;
      H[i][j + c + 1] -= 1;
      node sol;
      sol.x = i;
      sol.y = j;
      sol.l = c;
      ans.push_back(sol);
    }
  }
  check();
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].x << " " << ans[i].y << " " << ans[i].l << "\n";
}
