#include <bits/stdc++.h>
using namespace std;
long long up[1010][1010];
long long down[1010][1010];
long long left1[1010][1010];
long long right1[1010][1010];
char c[1010][1010];
long long dp[1010][1010];
long long row[1010][1010], col[1010][1010];
bool sel[1010][1010];
vector<pair<pair<long long, long long>, long long> > vc;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < 1010; i++)
    for (long long j = 0; j < 1010; j++) c[i][j] = '.';
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (c[i][j] == '*') {
        up[i][j] = up[i - 1][j] + 1;
        left1[i][j] = left1[i][j - 1] + 1;
      }
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--) {
      if (c[i][j] == '*') {
        down[i][j] = down[i + 1][j] + 1;
        right1[i][j] = right1[i][j + 1] + 1;
      }
    }
  }
  long long ans = -1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (c[i][j] == '*') {
        dp[i][j] = min({up[i][j], left1[i][j], right1[i][j], down[i][j]});
        if (dp[i][j] > 1) {
          dp[i][j]--;
          vc.push_back(make_pair(make_pair(i, j), dp[i][j]));
          row[i][j - dp[i][j]]++;
          row[i][j + dp[i][j] + 1]--;
          col[i - dp[i][j]][j]++;
          col[i + dp[i][j] + 1][j]--;
        }
      }
    }
  }
  bool flag = true;
  for (long long i = 1; i <= n; i++) {
    long long pre = 0;
    for (long long j = 1; j <= m; j++) {
      pre += row[i][j];
      if ((pre == 0 && c[i][j] == '*')) {
      } else {
        sel[i][j] = true;
      }
    }
  }
  for (long long j = 1; j <= m; j++) {
    long long pre = 0;
    for (long long i = 1; i <= n; i++) {
      pre += col[i][j];
      if (!sel[i][j] && c[i][j] == '*' && pre == 0) {
        flag = false;
      }
    }
  }
  if (!flag)
    cout << -1;
  else {
    cout << vc.size() << '\n';
    for (auto it : vc)
      cout << it.first.first << " " << it.first.second << " " << it.second
           << '\n';
  }
  return 0;
}
