#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char a[n][m];
  int b[n][m], c[n][m];
  int l[n][m], r[n][m], u[n][m], d[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      b[i][j] = 0;
      c[i][j] = 0;
      u[i][j] = 0;
      d[i][j] = 0;
      l[i][j] = 0;
      r[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i][0] == '.')
      l[i][0] = 0;
    else
      l[i][0] = 1;
    if (a[i][m - 1] == '.')
      r[i][m - 1] = 0;
    else
      r[i][m - 1] = 1;
  }
  for (int i = 0; i < m; i++) {
    if (a[0][i] == '.')
      u[0][i] = 0;
    else
      u[0][i] = 1;
    if (a[n - 1][i] == '.')
      d[n - 1][i] = 0;
    else
      d[n - 1][i] = 1;
  }
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      if (a[i][j] == '*') {
        u[i][j] = u[i - 1][j] + 1;
        l[i][j] = l[i][j - 1] + 1;
      } else {
        u[i][j] = 0;
        l[i][j] = 0;
      }
    }
  }
  for (int i = n - 2; i > 0; i--) {
    for (int j = m - 2; j > 0; j--) {
      if (a[i][j] == '*') {
        d[i][j] = d[i + 1][j] + 1;
        r[i][j] = r[i][j + 1] + 1;
      } else {
        d[i][j] = 0;
        r[i][j] = 0;
      }
    }
  }
  vector<pair<pair<int, int>, int> > o;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      int st = min(min(min(u[i][j], d[i][j]), l[i][j]), r[i][j]) - 1;
      if (st > 0) {
        o.push_back({{i, j}, st});
        b[i - st][j]++;
        if (i + st + 1 < n) b[i + st + 1][j]--;
        c[i][j - st]++;
        if (j + st + 1 < m) c[i][j + st + 1]--;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i > 0) b[i][j] += b[i - 1][j];
      if (j > 0) c[i][j] += c[i][j - 1];
      char x;
      if (b[i][j] > 0 || c[i][j] > 0)
        x = '*';
      else
        x = '.';
      if (a[i][j] != x) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << o.size() << endl;
  for (int i = 0; i < o.size(); i++) {
    cout << o[i].first.first + 1 << " " << o[i].first.second + 1 << " "
         << o[i].second << endl;
  }
}
