#include <bits/stdc++.h>
using namespace std;
const int S = 1e3 + 10;
int n, m, rig[S][S], lef[S][S], up[S][S], dow[S][S];
char tab[S][S];
int r[S][S], c[S][S], v;
vector<pair<pair<int, int>, int> > ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= m; b++) cin >> tab[a][b];
  }
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= m; b++) {
      if (tab[a][b] == '*')
        rig[a][b] = rig[a][b - 1] + 1;
      else
        rig[a][b] = 0;
    }
  }
  for (int a = 1; a <= n; a++) {
    for (int b = m; b >= 1; b--) {
      if (tab[a][b] == '*')
        lef[a][b] = lef[a][b + 1] + 1;
      else
        lef[a][b] = 0;
    }
  }
  for (int a = 1; a <= m; a++) {
    for (int b = 1; b <= n; b++) {
      if (tab[b][a] == '*')
        dow[b][a] = dow[b - 1][a] + 1;
      else
        dow[b][a] = 0;
    }
  }
  for (int a = 1; a <= m; a++) {
    for (int b = n; b >= 1; b--) {
      if (tab[b][a] == '*')
        up[b][a] = up[b + 1][a] + 1;
      else
        up[b][a] = 0;
    }
  }
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= m; b++) {
      v = min(min(rig[a][b], lef[a][b]), min(up[a][b], dow[a][b]));
      v--;
      if (v > 0) {
        ans.push_back(make_pair(make_pair(a, b), v));
        r[a][max(1, b - v)]++;
        r[a][min(m + 1, b + v + 1)]--;
        c[max(1, a - v)][b]++;
        c[min(n + 1, a + v + 1)][b]--;
      }
    }
  }
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= m; b++) r[a][b] += r[a][b - 1];
  }
  for (int a = 1; a <= m; a++) {
    for (int b = 1; b <= n; b++) c[b][a] += c[b - 1][a];
  }
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= m; b++) {
      if (tab[a][b] == '*' && !r[a][b] && !c[a][b]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << ans.size() << endl;
  for (int a = 0; a < ans.size(); a++)
    cout << ans[a].first.first << " " << ans[a].first.second << " "
         << ans[a].second << '\n';
  return 0;
}
