#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
const int maxn = 1010;
const int mod = 1000000;
const int inf = 0x3f3f3f3f;
const int INF = 0x7FFFFFFF;
void Mod(long long &x) { x %= mod; }
long long Min(long long a, long long b) { return a < b ? a : b; }
long long Max(long long a, long long b) { return a > b ? a : b; }
long long Abs(long long x) { return x >= 0 ? x : -x; }
int Random() {
  static int seed = 703;
  return seed = (int)(seed * 48271LL % 2147483647);
}
int n, m, ans = 0, ok = 1, sumx[maxn][maxn], sumy[maxn][maxn], sx[maxn][maxn],
          sy[maxn][maxn], vis[maxn][maxn];
char mp[maxn][maxn];
struct node {
  int x, y, r;
} data[maxn * maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  memset(sumx, 0, sizeof(sumx));
  memset(sumy, 0, sizeof(sumy));
  memset(vis, 0, sizeof(vis));
  memset(sx, 0, sizeof(sx));
  memset(sy, 0, sizeof(sy));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '*')
        sumx[i][j] = sumx[i][j - 1] + 1;
      else
        sumx[i][j] = sumx[i][j - 1];
    }
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) {
      if (mp[j][i] == '*')
        sumy[i][j] = sumy[i][j - 1] + 1;
      else
        sumy[i][j] = sumy[i][j - 1];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '*') {
        int l = 1, r = min(min(i - 1, j - 1), min(n - i, m - j));
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (sumx[i][j - 1] - sumx[i][j - mid - 1] == mid &&
              sumx[i][j + mid] - sumx[i][j] == mid &&
              sumy[j][i - 1] - sumy[j][i - mid - 1] == mid &&
              sumy[j][i + mid] - sumy[j][i] == mid)
            l = mid + 1;
          else
            r = mid - 1;
        }
        if (r != 0) {
          ans++;
          data[ans].x = i;
          data[ans].y = j;
          data[ans].r = r;
          sx[i][j - r]++;
          sx[i][j + r + 1]--;
          sy[j][i - r]++;
          sy[j][i + r + 1]--;
        }
      }
    }
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++) {
      cnt += sx[i][j];
      if (cnt == 0 && mp[i][j] == '*') vis[i][j] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    int cnt = 0;
    for (int j = 1; j <= n; j++) {
      cnt += sy[i][j];
      if (cnt == 0 && vis[j][i]) ok = 0;
    }
  }
  if (ok) {
    printf("%d\n", ans);
    for (int i = 1; i <= ans; i++)
      printf("%d %d %d\n", data[i].x, data[i].y, data[i].r);
  } else {
    printf("-1\n");
  }
  return 0;
}
