#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
struct node {
  int x, y, z;
};
char str[1005][1005];
int r[1005][1005], l[1005][1005], u[1005][1005], d[1005][1005],
    sum1[1005][1005], sum2[1005][1005];
int n, m;
vector<node> v;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '*') {
        u[i][j] = u[i - 1][j] + 1;
        l[i][j] = l[i][j - 1] + 1;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if (str[i][j] == '*') {
        d[i][j] = d[i + 1][j] + 1;
        r[i][j] = r[i][j + 1] + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '*') {
        int cnt = min(u[i][j], min(d[i][j], min(l[i][j], r[i][j])));
        if (cnt == 1) continue;
        sum1[i - cnt + 1][j] += 1;
        sum1[i + cnt][j] -= 1;
        sum2[i][j - cnt + 1] += 1;
        sum2[i][j + cnt] -= 1;
        node q;
        q.x = i;
        q.y = j;
        q.z = cnt - 1;
        v.push_back(q);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      sum1[i][j] += sum1[i - 1][j];
      sum2[i][j] += sum2[i][j - 1];
    }
  }
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '*') {
        if (sum1[i][j] == 0 && sum2[i][j] == 0) {
          flag = 1;
        }
      }
      if (flag) break;
    }
    if (flag) break;
  }
  if (flag)
    printf("-1\n");
  else {
    printf("%d\n", v.size());
    for (int i = 0; i < v.size(); i++) {
      printf("%d %d %d\n", v[i].x, v[i].y, v[i].z);
    }
  }
  return 0;
}
