#include <bits/stdc++.h>
using namespace std;
int SAG[1010][1010];
int AS[1010][1010];
int C[1010][1010];
int R[1010][1010];
int n, m;
char c[1010][1010];
vector<pair<pair<int, int>, int>> A;
int BS(int type, int x, int y) {
  int l = 1, r = 1000, mid, ret = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    if (type == 1 && x - mid >= 1 && C[x - 1][y] - C[x - mid - 1][y] == mid)
      l = mid + 1, ret = max(ret, mid);
    else if (type == 2 && x + mid <= n && C[x + mid][y] - C[x][y] == mid)
      l = mid + 1, ret = max(ret, mid);
    else if (type == 3 && y - mid >= 1 &&
             R[x][y - 1] - R[x][y - mid - 1] == mid)
      l = mid + 1, ret = max(ret, mid);
    else if (type == 4 && y + mid <= m && R[x][y + mid] - R[x][y] == mid)
      l = mid + 1, ret = max(ret, mid);
    else
      r = mid - 1;
  }
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int h = 1; h <= m; h++) {
      cin >> c[i][h];
      C[i][h] = C[i - 1][h];
      R[i][h] = R[i][h - 1];
      if (c[i][h] == '*') C[i][h]++, R[i][h]++;
    }
  for (int i = 1; i <= n; i++)
    for (int h = 1; h <= m; h++) {
      if (c[i][h] == '.') continue;
      int mn = 1e9;
      for (int j = 1; j <= 4; j++) mn = min(BS(j, i, h), mn);
      if (mn != 0) {
        A.push_back({{i, h}, mn});
        SAG[i][h - mn]++;
        SAG[i][h + mn + 1]--;
        AS[i - mn][h]++;
        AS[i + mn + 1][h]--;
      }
    }
  for (int i = 1; i <= n; i++)
    for (int h = 1; h <= m; h++) {
      SAG[i][h] += SAG[i][h - 1];
      AS[i][h] += AS[i - 1][h];
      if (c[i][h] == '*' && SAG[i][h] == 0 && AS[i][h] == 0) {
        cout << "-1";
        return 0;
      }
    }
  cout << A.size() << "\n";
  for (auto i : A)
    cout << i.first.first << " " << i.first.second << " " << i.second << "\n";
}
