#include <bits/stdc++.h>
using namespace std;
int n, m;
char brd[1000][1024];
vector<int> x, y, s;
int cnt[4][1000][1000];
set<int> rxy[1000], ryx[1000];
bool rem[1000][1000];
void draw(int _x, int _y, int _s) {
  x.push_back(_x + 1);
  y.push_back(_y + 1);
  s.push_back(_s);
  for (;;) {
    auto itr = rxy[_x].lower_bound(_y - _s);
    if (itr == rxy[_x].end()) break;
    if (*itr > _y + _s) break;
    rem[_x][*itr] = false;
    rxy[_x].erase(itr);
  }
  for (;;) {
    auto itr = ryx[_y].lower_bound(_x - _s);
    if (itr == ryx[_y].end()) break;
    if (*itr > _x + _s) break;
    rem[*itr][_y] = false;
    ryx[_y].erase(itr);
  }
}
int main(void) {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", brd[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (brd[i][j] == '*') {
        rxy[i].insert(j);
        ryx[j].insert(i);
        rem[i][j] = true;
      } else {
        rem[i][j] = false;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int t = 0;
      if (brd[i][j] == '*') {
        t++;
        if (j > 0) t += cnt[0][i][j - 1];
      }
      cnt[0][i][j] = t;
    }
    for (int j = m - 1; j >= 0; j--) {
      int t = 0;
      if (brd[i][j] == '*') {
        t++;
        if (j + 1 < m) t += cnt[1][i][j + 1];
      }
      cnt[1][i][j] = t;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      int t = 0;
      if (brd[i][j] == '*') {
        t++;
        if (i > 0) t += cnt[2][i - 1][j];
      }
      cnt[2][i][j] = t;
    }
    for (int i = n - 1; i >= 0; i--) {
      int t = 0;
      if (brd[i][j] == '*') {
        t++;
        if (i + 1 < n) t += cnt[3][i + 1][j];
      }
      cnt[3][i][j] = t;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int lv = 10000;
      for (int k = 0; k < 4; k++) lv = min(lv, cnt[k][i][j] - 1);
      if (lv <= 0) continue;
      draw(i, j, lv);
    }
  }
  bool flg = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (rem[i][j]) {
        flg = false;
      }
    }
  }
  if (flg) {
    int ss = s.size();
    printf("%d\n", ss);
    for (int i = 0; i < ss; i++) printf("%d %d %d\n", x[i], y[i], s[i]);
  } else {
    printf("-1");
  }
}
