#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
long long a[1005][1005], precol[1005][1005], sufcol[1005][1005],
    prerow[1005][1005], sufrow[1005][1005], dp1[1005][1005], dp2[1005][1005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  char c;
  vector<vector<long long> > ans;
  vector<long long> temp(3, 0);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> c;
      if (c == '*') a[i][j] = 1;
    }
  }
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    cnt = 0;
    for (long long j = 1; j <= m; j++) {
      prerow[i][j] = cnt;
      if (a[i][j])
        cnt++;
      else
        cnt = 0;
    }
  }
  for (long long i = 1; i <= n; i++) {
    cnt = 0;
    for (long long j = m; j >= 1; j--) {
      sufrow[i][j] = cnt;
      if (a[i][j])
        cnt++;
      else
        cnt = 0;
    }
  }
  for (long long i = 1; i <= m; i++) {
    cnt = 0;
    for (long long j = 1; j <= n; j++) {
      precol[j][i] = cnt;
      if (a[j][i])
        cnt++;
      else
        cnt = 0;
    }
  }
  for (long long i = 1; i <= m; i++) {
    cnt = 0;
    for (long long j = n; j >= 1; j--) {
      sufcol[j][i] = cnt;
      if (a[j][i])
        cnt++;
      else
        cnt = 0;
    }
  }
  long long tx;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      tx =
          min(sufcol[i][j], min(sufrow[i][j], min(prerow[i][j], precol[i][j])));
      if (a[i][j] and tx != 0) {
        dp1[i - tx][j] = 2 * tx + 1;
        dp2[i][j - tx] = 2 * tx + 1;
        temp[0] = i;
        temp[1] = j;
        temp[2] = tx;
        ans.push_back(temp);
      }
    }
  }
  cnt = 0;
  for (long long i = 1; i <= m; i++) {
    cnt = 0;
    for (long long j = 1; j <= n; j++) {
      cnt = max(dp1[j][i], cnt);
      if (cnt > 0) {
        dp1[j][i] = 1;
        cnt--;
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    cnt = 0;
    for (long long j = 1; j <= m; j++) {
      cnt = max(dp2[i][j], cnt);
      if (cnt > 0) {
        dp2[i][j] = 1;
        cnt--;
      }
    }
  }
  long long w = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++)
      if (a[i][j] != (dp1[i][j] | dp2[i][j])) w = 0;
  }
  if (w) {
    cout << ans.size() << '\n';
    for (long long i = 0; i < ans.size(); i++) {
      for (long long j = 0; j < 3; j++) cout << ans[i][j] << " ";
      cout << '\n';
    }
  } else
    cout << -1;
  return 0;
}
