#include <bits/stdc++.h>
using namespace std;
long long int x, y, t, m, n, i, l, j, d, k, w, u, c1;
long long int dp[1001][1001];
long long int right1[1001][1001], left1[1001][1001], down1[1001][1001],
    up1[1001][1001];
long long int a[1001][1001];
long long int b[1001][1001];
long long int c[1001][1001];
int main(void) {
  memset(dp, -1, sizeof dp);
  char ch;
  cin >> n >> m;
  for (i = (int)1; i < (int)n + 1; i++) {
    for (j = (int)1; j < (int)m + 1; j++) {
      cin >> ch;
      if (ch == '*')
        b[i][j] = 2;
      else
        b[i][j] = 1;
    }
  }
  for (i = (int)1; i < (int)n + 1; i++) {
    for (j = (int)1; j < (int)m + 1; j++) {
      if (i > 1) {
        if (b[i - 1][j] == 2) up1[i][j] += up1[i - 1][j] + 1;
      }
      if (j > 1) {
        if (b[i][j - 1] == 2) left1[i][j] += left1[i][j - 1] + 1;
      }
    }
  }
  for (i = (int)n; i >= (int)1; i--) {
    for (j = (int)m; j >= (int)1; j--) {
      if (i < n) {
        if (b[i + 1][j] == 2) down1[i][j] += down1[i + 1][j] + 1;
      }
      if (j < m) {
        if (b[i][j + 1] == 2) right1[i][j] += right1[i][j + 1] + 1;
      }
    }
  }
  memset(dp, -1, sizeof dp);
  for (i = (int)1; i < (int)n + 1; i++) {
    for (j = (int)1; j < (int)m + 1; j++) {
      if (b[i][j] == 2) {
        if ((x = min({down1[i][j], up1[i][j], left1[i][j], right1[i][j]})) !=
            0) {
          dp[i][j] = x;
          a[i][j - x] += 1;
          c[i - x][j] += 1;
          c[i + x + 1][j] -= 1;
          a[i][j + x + 1] -= 1;
        }
      }
    }
  }
  for (i = (int)1; i < (int)n + 1; i++) {
    for (j = (int)2; j < (int)m + 1; j++) {
      a[i][j] += a[i][j - 1];
    }
  }
  for (j = (int)1; j < (int)m + 1; j++) {
    for (i = (int)2; i < (int)n + 1; i++) {
      c[i][j] += c[i - 1][j];
    }
  }
  for (i = (int)1; i < (int)n + 1; i++) {
    for (j = (int)1; j < (int)m + 1; j++) {
      if (b[i][j] == 2 && dp[i][j] == -1 && (a[i][j] <= 0 && c[i][j] <= 0)) {
        cout << "-1"
             << "\n";
        return 0;
      }
    }
  }
  for (i = (int)1; i < (int)n + 1; i++) {
    for (j = (int)1; j < (int)m + 1; j++) {
      if (dp[i][j] != -1) k++;
    }
  }
  cout << k << "\n";
  for (i = (int)1; i < (int)n + 1; i++) {
    for (j = (int)1; j < (int)m + 1; j++) {
      if (dp[i][j] != -1) {
        cout << i << " " << j << " " << dp[i][j] << "\n";
      }
    }
  }
}
