#include <bits/stdc++.h>
using namespace std;
int up[1043][1043], down[1043][1043], lef[1043][1043], righ[1043][1043];
int hor[1043][1043], ver[1043][1043];
int fin_min(int i, int j) {
  return min(min(up[i][j], down[i][j]), min(lef[i][j], righ[i][j]));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> str(n);
  for (int i = 0; i < n; i++) cin >> str[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i - 1][j - 1] == '*') {
        up[i][j] = up[i - 1][j] + 1;
        lef[i][j] = lef[i][j - 1] + 1;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if (str[i - 1][j - 1] == '*') {
        down[i][j] = down[i + 1][j] + 1;
        righ[i][j] = righ[i][j + 1] + 1;
      }
    }
  }
  vector<pair<pair<int, int>, int>> ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = fin_min(i, j) - 1;
      if (x > 0) {
        ans.push_back(make_pair(make_pair(i, j), x));
        ver[i - x][j]++;
        hor[i][j - x]++;
        ver[i + x + 1][j]--;
        hor[i][j + x + 1]--;
      }
    }
  }
  bool an = true;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      ver[i][j] += ver[i - 1][j];
      hor[i][j] += hor[i][j - 1];
      if (str[i - 1][j - 1] == '*' && !(ver[i][j] || hor[i][j])) an = false;
    }
  if (an) {
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
      cout << ans[i].first.first << " " << ans[i].first.second << " "
           << ans[i].second << endl;
  } else {
    cout << "-1" << endl;
  }
}
