#include <bits/stdc++.h>
using namespace std;
bool arr[1010][1010];
bool dp[1010][1010];
int vtn[1010][1010];
int ntv[1010][1010];
int ltr[1010][1010];
int rtl[1010][1010];
int h[1010][1010];
int v[1010][1010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  char a;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a;
      if (a == '*') {
        arr[i][j] = true;
        dp[i][j] = true;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j - 1] && arr[i][j]) ltr[i][j] = ltr[i][j - 1] + 1;
      if (arr[i - 1][j] && arr[i][j]) vtn[i][j] = vtn[i - 1][j] + 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if (arr[i][j + 1] && arr[i][j]) rtl[i][j] = rtl[i][j + 1] + 1;
      if (arr[i + 1][j] && arr[i][j]) ntv[i][j] = ntv[i + 1][j] + 1;
    }
  }
  vector<pair<pair<int, int>, int> > ve;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j]) {
        int a = min(min(min(ltr[i][j], rtl[i][j]), vtn[i][j]), ntv[i][j]);
        if (a > 0) {
          ve.push_back(make_pair(make_pair(i, j), a));
        }
      }
    }
  }
  for (int i = 0; i < ve.size(); i++) {
    int in = ve[i].first.first;
    int jn = ve[i].first.second;
    int len = ve[i].second + 1;
    h[in][jn - len + 1]++;
    if (jn + len <= m) {
      h[in][jn + len]--;
    }
    v[in - len + 1][jn]++;
    if (in + len <= n) {
      v[in + len][jn]--;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i > 1) v[i][j] += v[i - 1][j];
      if (j > 1) h[i][j] += h[i][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if ((v[i][j] > 0) || (h[i][j]) > 0) {
        dp[i][j] = false;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (dp[i][j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << ve.size() << endl;
  for (int i = 0; i < ve.size(); i++) {
    int in = ve[i].first.first;
    int jn = ve[i].first.second;
    int len = ve[i].second;
    cout << in << " " << jn << " " << len << "\n";
  }
  return 0;
}
