#include <bits/stdc++.h>
using namespace std;
const int mn = 1005;
int n, m;
char s[mn][mn];
int u[mn][mn], d[mn][mn];
int l[mn][mn], r[mn][mn];
bool c[mn][mn];
int in[mn][mn];
struct star {
  int x, y, l;
};
vector<star> ans;
bool judge() {
  int t = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (in[i][j]) t = max(t, in[i][j]);
      if (t >= 0) c[i][j] = 1;
      t--;
    }
  }
  t = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = m; j; j--) {
      if (in[i][j]) t = max(t, in[i][j]);
      if (t >= 0) c[i][j] = 1;
      t--;
    }
  }
  t = -1;
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      if (in[i][j]) t = max(t, in[i][j]);
      if (t >= 0) c[i][j] = 1;
      t--;
    }
  }
  t = -1;
  for (int j = 1; j <= m; j++) {
    for (int i = n; i; i--) {
      if (in[i][j]) t = max(t, in[i][j]);
      if (t >= 0) c[i][j] = 1;
      t--;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '*' && c[i][j] == 0) return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '*')
        l[i][j] = l[i][j - 1] + 1;
      else
        l[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j; j--) {
      if (s[i][j] == '*')
        r[i][j] = r[i][j + 1] + 1;
      else
        r[i][j] = 0;
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      if (s[i][j] == '*')
        u[i][j] = u[i - 1][j] + 1;
      else
        u[i][j] = 0;
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = n; i; i--) {
      if (s[i][j] == '*')
        d[i][j] = d[i + 1][j] + 1;
      else
        d[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '*') {
        int v = min({u[i][j], d[i][j], l[i][j], r[i][j]}) - 1;
        in[i][j] = v;
        if (v > 0) ans.push_back(star{i, j, v});
      }
    }
  }
  if (!judge()) {
    puts("-1");
    return 0;
  }
  printf("%d\n", ans.size());
  for (auto &i : ans) {
    printf("%d %d %d\n", i.x, i.y, i.l);
  }
  return 0;
}
