#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
long long n, m;
vector<string> draw(vector<pair<pair<long long, long long>, long long>>& ans) {
  vector<string> f(n, string(m, '.'));
  vector<vector<long long>> ver(n, vector<long long>(m));
  vector<vector<long long>> hor(n, vector<long long>(m));
  for (auto it : ans) {
    long long x = it.first.first;
    long long y = it.first.second;
    long long len = it.second;
    ver[x - len][y]++;
    if (x + len + 1 < n) ver[x + len + 1][y]--;
    hor[x][y - len]++;
    if (y + len + 1 < m) hor[x][y + len + 1]--;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (i > 0) ver[i][j] += ver[i - 1][j];
      if (j > 0) hor[i][j] += hor[i][j - 1];
      if (ver[i][j] > 0 || hor[i][j] > 0) f[i][j] = '*';
    }
  }
  return f;
}
void solve() {
  cin >> n >> m;
  vector<string> s(n);
  for (long long i = 0; i < n; i++) cin >> s[i];
  vector<vector<long long>> left(n, vector<long long>(m));
  vector<vector<long long>> right(n, vector<long long>(m));
  vector<vector<long long>> up(n, vector<long long>(m));
  vector<vector<long long>> down(n, vector<long long>(m));
  for (long long i = 0; i < m; i++) {
    up[0][i] = (s[0][i] == '*');
    down[n - 1][i] = (s[n - 1][i] == '*');
  }
  for (long long i = 0; i < n; i++) {
    left[i][0] = (s[i][0] == '*');
    right[i][m - 1] = (s[i][m - 1] == '*');
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j < m; j++) {
      if (s[i][j] == '*') {
        up[i][j] = up[i - 1][j] + 1;
        left[i][j] = left[i][j - 1] + 1;
      }
    }
  }
  for (long long i = n - 2; i >= 0; i--) {
    for (long long j = m - 2; j >= 0; j--) {
      if (s[i][j] == '*') {
        down[i][j] = down[i + 1][j] + 1;
        right[i][j] = right[i][j + 1] + 1;
      }
    }
  }
  vector<pair<pair<long long, long long>, long long>> ans;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[i][j] == '*') {
        long long len =
            min(min(left[i][j], up[i][j]), min(right[i][j], down[i][j])) - 1;
        if (len > 0) ans.push_back({{i, j}, len});
      }
    }
  }
  if (draw(ans) != s) {
    cout << "-1\n";
    return;
  }
  cout << (long long)((ans).size()) << "\n";
  for (auto x : ans) {
    cout << x.first.first + 1 << " " << x.first.second + 1 << " " << x.second
         << "\n";
  }
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
