#include <bits/stdc++.h>
using namespace std;
int leftRight[1005][1005], topDown[1005][1005];
int rightLeft[1005][1005], bottomUp[1005][1005];
int leftRightSum[1005][1005], topDownSum[1005][1005];
string grid[1005];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> grid[i];
  for (int i = 0; i < n; i++) {
    int left = -1;
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*')
        leftRight[i][j] = left;
      else
        left = j;
    }
  }
  for (int i = 0; i < n; i++) {
    int right = m;
    for (int j = m - 1; j >= 0; j--) {
      if (grid[i][j] == '*')
        rightLeft[i][j] = right;
      else
        right = j;
    }
  }
  for (int i = 0; i < m; i++) {
    int top = -1;
    for (int j = 0; j < n; j++) {
      if (grid[j][i] == '*')
        topDown[j][i] = top;
      else
        top = j;
    }
  }
  for (int i = 0; i < m; i++) {
    int bottom = n;
    for (int j = n - 1; j >= 0; j--) {
      if (grid[j][i] == '*')
        bottomUp[j][i] = bottom;
      else
        bottom = j;
    }
  }
  vector<int> is, js, sij;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*') {
        int a = i - topDown[i][j] - 1;
        int b = bottomUp[i][j] - i - 1;
        int c = j - leftRight[i][j] - 1;
        int d = rightLeft[i][j] - j - 1;
        int sizeij = min(a, min(b, min(c, d)));
        if (sizeij > 0) {
          leftRightSum[i][j - sizeij] += 1;
          leftRightSum[i][j + sizeij + 1] -= 1;
          topDownSum[i - sizeij][j] += 1;
          topDownSum[i + sizeij + 1][j] -= 1;
          is.push_back(i + 1);
          js.push_back(j + 1);
          sij.push_back(sizeij);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j > 0)
        leftRightSum[i][j] = leftRightSum[i][j] + leftRightSum[i][j - 1];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (i > 0) topDownSum[i][j] = topDownSum[i][j] + topDownSum[i - 1][j];
    }
  }
  bool isPossible = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*') {
        if (topDownSum[i][j] < 1 && leftRightSum[i][j] < 1) isPossible = false;
      } else {
        if (topDownSum[i][j] != 0 || leftRightSum[i][j] != 0)
          isPossible = false;
      }
    }
  }
  if (isPossible) {
    cout << is.size() << "\n";
    for (int i = 0; i < is.size(); i++) {
      cout << is[i] << " " << js[i] << " " << sij[i] << "\n";
    }
  } else {
    cout << "-1\n";
  }
  return 0;
}
