#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 77;
bool M[N][N];
int n, m, down[N][N], up[N][N], left1[N][N], right1[N][N], num[N][N],
    best[N][N];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
char c[N][N];
vector<pair<pair<int, int>, int> > A;
priority_queue<pair<int, pair<int, int> > > pq;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '*') {
        left1[i][j] = left1[i][j - 1] + 1;
        down[i][j] = down[i - 1][j] + 1;
      }
    }
    for (int j = m; j > 0; j--) {
      if (c[i][j] == '*') {
        right1[i][j] = right1[i][j + 1] + 1;
      }
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '*') {
        up[i][j] = up[i + 1][j] + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int t = min(right1[i][j], left1[i][j]);
      t = min(t, up[i][j]);
      t = min(t, down[i][j]);
      t--;
      if (t <= 0) {
        continue;
      }
      num[i][j] = t;
      A.push_back(make_pair(make_pair(i, j), t));
      pq.push(make_pair(t, make_pair(i, j)));
    }
  }
  while (pq.size()) {
    int X = pq.top().second.first, Y = pq.top().second.second,
        cost = pq.top().first;
    pq.pop();
    if (M[X][Y]) {
      continue;
    }
    M[X][Y] = 1;
    if (cost == 0) {
      continue;
    }
    for (int i = 0; i < 4; i++) {
      int nx = X + dx[i], ny = Y + dy[i];
      if (c[nx][ny] == '.' || nx < 1 || ny < 1 || nx > n || ny > m ||
          M[nx][ny]) {
        continue;
      }
      pq.push(make_pair(cost - 1, make_pair(nx, ny)));
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!M[i][j] && c[i][j] == '*') {
        return cout << -1, 0;
      }
    }
  }
  cout << (int)A.size() << '\n';
  for (auto x : A) {
    cout << x.first.first << ' ' << x.first.second << ' ' << x.second << '\n';
  }
  return 0;
}
