#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5;
long long a[N][N], l[N][N], r[N][N], u[N][N], d[N][N], sum[N][N];
long long n, m;
char ch;
int32_t main() {
  cin >> n >> m;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      cin >> ch;
      if (ch == '*') a[i][j] = 1;
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (a[i][j]) {
        l[i][j] = l[i][j - 1] + 1;
        u[i][j] = u[i - 1][j] + 1;
      }
    }
  }
  for (long long i = n; i > 0; i--) {
    for (long long j = m; j >= 0; j--) {
      if (a[i][j]) {
        r[i][j] = 1 + r[i][j + 1];
        d[i][j] = 1 + d[i + 1][j];
      }
    }
  }
  vector<pair<long long, pair<long long, long long> > > ans;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      long long t1 = min(l[i][j], min(r[i][j], min(u[i][j], d[i][j])));
      if (t1 > 1) {
        sum[i][j] = t1;
        ans.emplace_back(i, make_pair(j, t1 - 1));
      }
      l[i][j] = 0;
      r[i][j] = 0;
      u[i][j] = 0;
      d[i][j] = 0;
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      l[i][j] = max(sum[i][j], l[i][j - 1] - 1);
      u[i][j] = max(sum[i][j], u[i - 1][j] - 1);
    }
  }
  for (long long i = n; i > 0; i--) {
    for (long long j = m; j >= 0; j--) {
      r[i][j] = max(sum[i][j], r[i][j + 1] - 1);
      d[i][j] = max(sum[i][j], d[i + 1][j] - 1);
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (a[i][j] == 0) continue;
      if (l[i][j] || r[i][j] || u[i][j] || d[i][j]) continue;
      {
        cout << "-1";
        return 0;
      }
    }
  }
  cout << ans.size() << "\n";
  for (auto i : ans)
    cout << i.first << " " << i.second.first << " " << i.second.second << "\n";
}
