#include <bits/stdc++.h>
using namespace std;
int n, m, sm[1002][1002][2], co[1002][1002][2][2];
bool vis[1002][1002];
char a[1002][1002];
vector<pair<pair<int, int>, int> > v;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '*') co[i][j][0][0] = j == 0 ? 1 : co[i][j - 1][0][0] + 1;
    }
    for (int j = m - 1; j >= 0; j--) {
      if (a[i][j] == '*') co[i][j][0][1] = co[i][j + 1][0][1] + 1;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (a[i][j] == '*') co[i][j][1][0] = i == 0 ? 1 : co[i - 1][j][1][0] + 1;
    }
    for (int i = n - 1; i >= 0; i--) {
      if (a[i][j] == '*') co[i][j][1][1] = co[i + 1][j][1][1] + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '*') {
        int c1 = j == 0 ? 0 : co[i][j - 1][0][0];
        int c2 = co[i][j + 1][0][1];
        int c3 = i == 0 ? 0 : co[i - 1][j][1][0];
        int c4 = co[i + 1][j][1][1];
        int c = min(c1, min(c2, min(c3, c4)));
        if (c > 0) {
          v.push_back({{i + 1, j + 1}, c});
          sm[i - c][j][0]++;
          sm[i + c + 1][j][0]--;
          sm[i][j - c][1]++;
          sm[i][j + c + 1][1]--;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < m; j++) {
      c += sm[i][j][1];
      if (c > 0) vis[i][j] = 1;
    }
  }
  for (int j = 0; j < m; j++) {
    int c = 0;
    for (int i = 0; i < n; i++) {
      c += sm[i][j][0];
      if (c > 0) vis[i][j] = 1;
      if (vis[i][j] == 0 && a[i][j] == '*') return cout << -1, 0;
    }
  }
  printf("%d\n", v.size());
  for (int i = 0; i < v.size(); i++)
    printf("%d %d %d\n", v[i].first.first, v[i].first.second, v[i].second);
  return 0;
}
