#include <bits/stdc++.h>
using namespace std;
char mat[1007][1007];
int up[1007][1007];
int dow[1007][1007];
int lef[1007][1007];
int rig[1007][1007];
int sz[1007][1007];
int cnt[2][1007][1007];
int flag[1007][1007];
int n, m;
inline int get(int vec[1007][1007], int i, int j) {
  if (i >= 0 and j >= 0 and i < n and j < m)
    return vec[i][j];
  else
    return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> mat[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mat[i][j] == '.')
        lef[i][j] = 0;
      else
        lef[i][j] = 1 + get(lef, i, j - 1);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = m - 1; j >= 0; --j) {
      if (mat[i][j] == '.')
        rig[i][j] = 0;
      else
        rig[i][j] = 1 + get(rig, i, j + 1);
    }
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; i++) {
      if (mat[i][j] == '.')
        up[i][j] = 0;
      else
        up[i][j] = 1 + get(up, i - 1, j);
    }
  }
  int res = 0;
  for (int j = 0; j < m; ++j) {
    for (int i = n - 1; i >= 0; i--) {
      if (mat[i][j] == '.')
        dow[i][j] = 0;
      else
        dow[i][j] = 1 + get(dow, i + 1, j);
      sz[i][j] = min({up[i][j], dow[i][j], lef[i][j], rig[i][j]});
      int t = sz[i][j];
      if (t > 1) {
        res++;
        cnt[0][i][j - t + 1]++;
        cnt[0][i][j + t]--;
        cnt[1][i - t + 1][j]++;
        cnt[1][i + t][j]--;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    int cur = 0;
    for (int j = 0; j < m; ++j) {
      cur += cnt[0][i][j];
      if (mat[i][j] == '*') flag[i][j] = flag[i][j] or cur > 0;
    }
  }
  for (int j = 0; j < m; ++j) {
    int cur = 0;
    for (int i = 0; i < n; i++) {
      cur += cnt[1][i][j];
      if (mat[i][j] == '*') flag[i][j] = flag[i][j] or cur > 0;
    }
  }
  int ok = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mat[i][j] == '*') ok = ok and flag[i][j];
    }
  }
  if (!ok)
    cout << -1 << endl;
  else {
    cout << res << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        int t = sz[i][j];
        if (t > 1) {
          cout << i + 1 << ' ' << j + 1 << ' ' << t - 1 << '\n';
        }
      }
    }
  }
}
