#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(20);
  long long int n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  vector<vector<long long int>> a(n, vector<long long int>(m, 0));
  vector<vector<long long int>> l(n, vector<long long int>(m, 0)),
      r(n, vector<long long int>(m, 0)), u(n, vector<long long int>(m, 0)),
      d(n, vector<long long int>(m, 0));
  long long int ans = 0;
  vector<pair<pair<long long int, long long int>, long long int>> s;
  for (long long int i = 0; i < n; i++) {
    for (auto j = 1; j <= m - 1; j++) {
      if (v[i][j - 1] == '*') {
        l[i][j] = l[i][j - 1] + 1;
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (auto j = m - 2; j >= (0); --j) {
      if (v[i][j + 1] == '*') {
        r[i][j] = r[i][j + 1] + 1;
      }
    }
  }
  for (auto i = 1; i <= n - 1; i++) {
    for (long long int j = 0; j < m; j++) {
      if (v[i - 1][j] == '*') {
        u[i][j] = u[i - 1][j] + 1;
      }
    }
  }
  for (auto i = n - 2; i >= (0); --i) {
    for (long long int j = 0; j < m; j++) {
      if (v[i + 1][j] == '*') {
        d[i][j] = d[i + 1][j] + 1;
      }
    }
  }
  for (auto i = 1; i <= n - 2; i++) {
    for (auto j = 1; j <= m - 2; j++) {
      if (v[i][j] == '*') {
        long long int k = min(min(u[i][j], d[i][j]), min(l[i][j], r[i][j]));
        if (k) {
          ans++;
          s.push_back({{i, j}, k});
        }
      }
    }
  }
  vector<vector<long long int>> star(n, vector<long long int>(m, 0));
  for (auto i : s) star[i.first.first][i.first.second] = i.second;
  long long int flag = 1;
  for (long long int i = 0; i < n; i++) {
    long long int x = 0;
    for (long long int j = 0; j < m; j++) {
      if (star[i][j] > x || (star[i][j] == x && x)) {
        x = star[i][j];
        a[i][j] = 1;
      } else if (x) {
        a[i][j] = 1;
        x--;
      }
    }
    x = 0;
    for (auto j = m - 1; j >= (0); --j) {
      if (star[i][j] > x || (star[i][j] == x && x)) {
        x = star[i][j];
        a[i][j] = 1;
      } else if (x) {
        a[i][j] = 1;
        x--;
      }
    }
  }
  for (long long int j = 0; j < m; j++) {
    long long int x = 0;
    for (long long int i = 0; i < n; i++) {
      if (star[i][j] > x || (star[i][j] == x && x)) {
        x = star[i][j];
        a[i][j] = 1;
      } else if (x) {
        a[i][j] = 1;
        x--;
      }
    }
    x = 0;
    for (auto i = n - 1; i >= (0); --i) {
      if (star[i][j] > x || (star[i][j] == x && x)) {
        x = star[i][j];
        a[i][j] = 1;
      } else if (x) {
        a[i][j] = 1;
        x--;
      }
    }
  }
  for (long long int i = 0; i < n; i++)
    ;
  for (long long int i = 0; i < n; i++)
    ;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (v[i][j] == '*' && a[i][j] == 0) {
        flag = 0;
        break;
      }
    }
  }
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  for (long long int i = 0; i < ans; i++) {
    cout << s[i].first.first + 1 << ' ' << s[i].first.second + 1 << ' '
         << s[i].second << endl;
  };
  return 0;
}
