#include <bits/stdc++.h>
using namespace std;
const int MN = 1000 + 100;
bool g[MN][MN];
int d[4][MN][MN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c == '*') {
        g[i][j] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j]) {
        d[0][i][j] = 1;
        d[1][i][j] = 1;
        if (i) {
          d[0][i][j] += d[0][i - 1][j];
        }
        if (j) {
          d[1][i][j] += d[1][i][j - 1];
        }
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (g[i][j]) {
        d[2][i][j] = 1;
        d[3][i][j] = 1;
        d[2][i][j] += d[2][i + 1][j];
        d[3][i][j] += d[3][i][j + 1];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      d[0][i][j] = min(d[0][i][j], d[1][i][j]);
      d[0][i][j] = min(d[0][i][j], d[2][i][j]);
      d[0][i][j] = min(d[0][i][j], d[3][i][j]);
      if (d[0][i][j] < 2) {
        d[0][i][j] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int hav = 0;
    for (int j = 0; j < m; j++) {
      hav = max(hav, d[0][i][j]);
      if (hav) {
        g[i][j] = 0;
      }
      hav = max(0, hav - 1);
    }
    hav = 0;
    for (int j = m - 1; j >= 0; j--) {
      hav = max(hav, d[0][i][j]);
      if (hav) {
        g[i][j] = 0;
      }
      hav = max(0, hav - 1);
    }
  }
  for (int j = 0; j < m; j++) {
    int hav = 0;
    for (int i = 0; i < n; i++) {
      hav = max(hav, d[0][i][j]);
      if (hav) {
        g[i][j] = 0;
      }
      hav = max(0, hav - 1);
    }
    hav = 0;
    for (int i = n - 1; i >= 0; i--) {
      hav = max(hav, d[0][i][j]);
      if (hav) {
        g[i][j] = 0;
      }
      hav = max(0, hav - 1);
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j]) {
        cout << -1;
        return 0;
      }
      if (d[0][i][j]) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (d[0][i][j]) {
        cout << i + 1 << " " << j + 1 << " " << d[0][i][j] - 1 << endl;
      }
    }
  }
}
