#include <bits/stdc++.h>
using namespace std;
vector<string> vec(1001);
int up[1001][1001], down[1001][1001], lef[1001][1001], righ[1001][1001];
int arr[1001][1001], brr[1001][1001], ans[1001][1001];
int n, m;
int find_min(int row, int col) {
  return min(min(up[row][col], down[row][col]),
             min(lef[row][col], righ[row][col]));
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    vec[i] = str;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vec[i - 1][j] == '*') up[i][j] = up[i - 1][j] + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (vec[i][j - 1] == '*') lef[i][j] = lef[i][j - 1] + 1;
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (vec[i + 1][j] == '*') down[i][j] = down[i + 1][j] + 1;
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = m - 2; j >= 0; j--) {
      if (vec[i][j + 1] == '*') righ[i][j] = righ[i][j + 1] + 1;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vec[i][j] == '.') continue;
      int sizee = find_min(i, j);
      if (sizee) {
        count++;
        ans[i][j] = sizee;
        arr[i - sizee][j] += 1;
        arr[i + sizee + 1][j] -= 1;
        brr[i][j - sizee] += 1;
        brr[i][j + sizee + 1] -= 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i - 1 >= 0) {
        arr[i][j] += arr[i - 1][j];
      }
      if (j - 1 >= 0) {
        brr[i][j] += brr[i][j - 1];
      }
      if (vec[i][j] == '*' && brr[i][j] == 0 && arr[i][j] == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  cout << count << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (ans[i][j] == 0) continue;
      printf("%d %d %d\n", i + 1, j + 1, ans[i][j]);
    }
  }
  return 0;
}
