#include <bits/stdc++.h>
using namespace std;
const int mx = 1002;
int left_[mx][mx], right_[mx][mx], up[mx][mx], down[mx][mx];
vector<string> mat;
int n, m;
void pre() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '*') {
        left_[i][j] = (j == 0) ? 1 : (left_[i][j - 1] + 1);
        up[i][j] = (i == 0) ? 1 : (up[i - 1][j] + 1);
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (mat[i][j] == '*') {
        down[i][j] = (i == n - 1) ? 1 : (down[i + 1][j] + 1);
        right_[i][j] = (j == m - 1) ? 1 : (right_[i][j + 1] + 1);
      }
    }
  }
}
void read() {
  cin >> n >> m;
  string s;
  mat.clear();
  for (int i = 0; i < n; i++) {
    cin >> s;
    mat.push_back(s);
  }
}
vector<string> draw(vector<pair<pair<int, int>, int>> ans) {
  vector<string> trans(n, string(m, '.'));
  vector<vector<int>> ver(n, vector<int>(m, 0));
  vector<vector<int>> hor(n, vector<int>(m, 0));
  for (auto x : ans) {
    int i = x.first.first - 1;
    int j = x.first.second - 1;
    int val = x.second;
    hor[i][j - val]++;
    if (j + val + 1 < m) {
      hor[i][j + val + 1]--;
    }
    ver[i - val][j]++;
    if (i + val + 1 < n) {
      ver[i + val + 1][j]--;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j > 0) {
        hor[i][j] += hor[i][j - 1];
      }
      if (i > 0) {
        ver[i][j] += ver[i - 1][j];
      }
      if (hor[i][j] > 0 || ver[i][j] > 0) {
        trans[i][j] = '*';
      }
    }
  }
  return trans;
}
void solve() {
  read();
  pre();
  vector<pair<pair<int, int>, int>> ans;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      if (mat[i][j] == '*') {
        int val =
            min(min(up[i][j], down[i][j]), min(left_[i][j], right_[i][j])) - 1;
        if (val > 0) {
          ans.push_back(make_pair(make_pair(i + 1, j + 1), val));
        }
      }
    }
  }
  vector<string> trans = draw(ans);
  if (trans == mat) {
    cout << ans.size() << "\n";
    for (pair<pair<int, int>, int> x : ans) {
      cout << x.first.first << " " << x.first.second << " " << x.second << "\n";
    }
  } else {
    cout << -1 << endl;
  }
}
int main() {
  solve();
  return 0;
}
