#include <bits/stdc++.h>
using namespace std;
const long long int N = 1000005;
using namespace std;
long long int power(long long int x, long long int y, long long int m) {
  if (y == 0) return 1;
  long long int p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
char c[1005][1005];
long long int l[1005][1005], r[1005][1005], u[1005][1005], d[1005][1005],
    pre[1005][1005], suf[1005][1005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int dx[] = {1, 0, -1, 0};
  long long int dy[] = {0, 1, 0, -1};
  vector<pair<pair<long long int, long long int>, long long int>> v;
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(u, 0, sizeof(u));
  memset(d, 0, sizeof(d));
  memset(pre, 0, sizeof(pre));
  memset(suf, 0, sizeof(suf));
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++)
    for (long long int j = 1; j <= m; j++) cin >> c[i][j];
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (c[i][j] == '*') {
        l[i][j] += l[i][j - 1] + 1;
        d[i][j] += d[i - 1][j] + 1;
      }
    }
  }
  for (long long int i = n; i >= 1; i--) {
    for (long long int j = m; j >= 1; j--) {
      if (c[i][j] == '*') {
        r[i][j] += r[i][j + 1] + 1;
        u[i][j] += u[i + 1][j] + 1;
      }
    }
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (c[i][j] == '*') {
        long long int ll = min(r[i][j], min(u[i][j], min(l[i][j], d[i][j])));
        if (ll > 1) {
          v.push_back(make_pair(make_pair(i, j), ll - 1));
          pre[i][j - ll + 1]++;
          pre[i][j + ll]--;
          suf[i - ll + 1][j]++;
          suf[i + ll][j]--;
        }
      }
    }
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      pre[i][j] += pre[i][j - 1];
      suf[i][j] += suf[i - 1][j];
    }
  }
  long long int oOOoOooOOoOOoO = 0;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (c[i][j] == '*' && pre[i][j] == 0 && suf[i][j] == 0) {
        oOOoOooOOoOOoO = 1;
        break;
      }
    }
    if (oOOoOooOOoOOoO) break;
  }
  if (oOOoOooOOoOOoO)
    cout << -1 << endl;
  else {
    cout << v.size() << endl;
    for (auto it : v)
      cout << it.first.first << ' ' << it.first.second << ' ' << it.second
           << endl;
  }
  return 0;
}
