#include <bits/stdc++.h>
using namespace std;
const int maxn = 1003;
bool comp(long long a, long long b) {
  if (a > b) return 1;
  return 0;
}
int up[maxn][maxn], dn[maxn][maxn], ri[maxn][maxn], le[maxn][maxn],
    hr[maxn][maxn], ver[maxn][maxn], mark[maxn][maxn];
int n, m;
char a[maxn][maxn];
void ups() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '*')
        up[i][j] = up[i - 1][j] + 1;
      else
        up[i][j] = 0;
    }
  }
}
void dns() {
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '*')
        dn[i][j] = dn[i + 1][j] + 1;
      else
        dn[i][j] = 0;
    }
  }
}
void ris() {
  for (int j = m; j >= 1; j--) {
    for (int i = 1; i <= n; i++) {
      if (a[i][j] == '*')
        ri[i][j] = ri[i][j + 1] + 1;
      else
        ri[i][j] = 0;
    }
  }
}
void les() {
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      if (a[i][j] == '*') le[i][j] = le[i][j - 1] + 1;
    }
  }
}
void check() {
  int i, j;
  for (j = 1; j <= m; j++) {
    for (i = 1; i <= n; i++) {
      ver[i][j] += ver[i][j - 1];
      if (ver[i][j] > 0) mark[i][j] = 1;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      hr[i][j] += hr[i - 1][j];
      if (hr[i][j] > 0) mark[i][j] = 1;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '*') {
        if (mark[i][j] == 0) {
          cout << -1;
          exit(0);
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, i, j, k, l;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) cin >> a[i][j];
  }
  ups();
  dns();
  ris();
  les();
  vector<int> x, y, si;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '*') {
        int cur = 1e7;
        cur = min(cur, dn[i + 1][j]);
        cur = min(cur, up[i - 1][j]);
        cur = min(cur, ri[i][j + 1]);
        cur = min(cur, le[i][j - 1]);
        if (cur > 0) {
          hr[i - cur][j] += 1;
          ver[i][j - cur] += 1;
          hr[i + cur + 1][j] -= 1;
          ver[i][j + cur + 1] -= 1;
          x.push_back(i);
          y.push_back(j);
          si.push_back(cur);
        }
      }
    }
  }
  check();
  cout << si.size() << "\n";
  if (si.size()) {
    for (i = 0; i < x.size(); i++) {
      cout << x[i] << " " << y[i] << " " << si[i] << "\n";
    }
  }
}
