#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
using namespace std;
void TestCase() {
  int n, m;
  cin >> n >> m;
  char g[n][m], h[n][m];
  int f[n][m], l[n][m], r[n][m], u[n][m], d[n][m];
  vector<pair<pair<int, int>, int> > ans;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
      h[i][j] = '.';
      f[i][j] = 0;
      l[i][j] = 0;
      r[i][j] = 0;
      u[i][j] = 0;
      d[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i - 1 >= 0) {
        if (g[i - 1][j] == '*') u[i][j] = 1 + u[i - 1][j];
      }
      if (j - 1 >= 0) {
        if (g[i][j - 1] == '*') l[i][j] = 1 + l[i][j - 1];
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (i + 1 < n) {
        if (g[i + 1][j] == '*') d[i][j] = 1 + d[i + 1][j];
      }
      if (j + 1 < m) {
        if (g[i][j + 1] == '*') r[i][j] = 1 + r[i][j + 1];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int k = min({l[i][j], u[i][j], d[i][j], r[i][j]});
      if (k && g[i][j] == '*') {
        ans.push_back({{i + 1, j + 1}, k});
        f[i - k][j]++;
        if (i + k + 1 < n) {
          f[i + k + 1][j]--;
        }
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int cur = 0;
    for (int i = 0; i < n; i++) {
      cur += f[i][j];
      if (cur > 0) h[i][j] = '*';
    }
    for (int i = 0; i < n; i++) f[i][j] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int k = min({l[i][j], u[i][j], d[i][j], r[i][j]});
      if (k && g[i][j] == '*') {
        f[i][j - k]++;
        if (j + k + 1 < m) {
          f[i][j + k + 1]--;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int cur = 0;
    for (int j = 0; j < m; j++) {
      cur += f[i][j];
      if (cur > 0) h[i][j] = '*';
    }
  }
  bool ok = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] != h[i][j]) ok = false;
    }
  }
  if (ok) {
    cout << (int)ans.size() << "\n";
    for (auto i : ans)
      cout << i.first.first << " " << i.first.second << " " << i.second << "\n";
  } else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int T = 1;
  while (T--) {
    TestCase();
    cout << "\n";
  }
  return 0;
}
