#include <bits/stdc++.h>
using namespace std;
int __gcd(int a, int b) { return (a % b) ? __gcd(b, a % b) : b; }
void solve() {
  int n, m;
  cin >> n >> m;
  string s[n];
  for (auto& j : s) cin >> j;
  int a[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++) {
      l[i][j] = r[i][j] = u[i][j] = d[i][j] = a[i][j] = 0;
      if (s[i][j] == '*') l[i][j] = r[i][j] = u[i][j] = d[i][j] = a[i][j] = 1;
    }
  for (int j = 0; j < m; j++) {
    for (int i = n - 2; i >= 0; i--)
      if (a[i][j] == 1) u[i][j] += u[i + 1][j];
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++)
      if (a[i][j] == 1) d[i][j] += d[i - 1][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++)
      if (a[i][j] == 1) r[i][j] += r[i][j - 1];
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 2; j >= 0; j--)
      if (a[i][j] == 1) l[i][j] += l[i][j + 1];
  }
  stack<tuple<int, int, int> > st;
  int p[n + 1][m];
  int q[n][m + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i != n) q[i][j] = 0;
      if (j != m) p[i][j] = 0;
    }
  }
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      if (a[i][j]) {
        int k = min({u[i + 1][j], d[i - 1][j], l[i][j + 1], r[i][j - 1]});
        if (k == 0) continue;
        p[i - k][j] += 1;
        p[i + k + 1][j] -= 1;
        q[i][j - k] += 1;
        q[i][j + k + 1] -= 1;
        if (k) {
          st.push({i, j, k});
        }
      }
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++) {
      p[i][j] += p[i - 1][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      q[i][j] += q[i][j - 1];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      p[i][j] += q[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '*' and p[i][j])
        continue;
      else if (s[i][j] == '*' or p[i][j]) {
        cout << "-1\n";
        return;
      }
    }
  }
  int pp, qq, rr;
  cout << (int)st.size() << "\n";
  while (!st.empty()) {
    tie(pp, qq, rr) = st.top();
    st.pop();
    cout << pp + 1 << " " << qq + 1 << " " << rr << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
