#include <bits/stdc++.h>
using namespace std;
string s[1010];
int r[1010][1010], l[1010][1010], u[1010][1010], d[1010][1010], an[1010][1010],
    ans[1010][1010];
vector<pair<int, pair<int, int>>> v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    int c = -1;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '*') {
        if (c == -1) {
          c = 1;
        } else {
          c++;
        }
        l[i][j] = c;
      } else {
        c = -1;
        l[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int c = -1;
    for (int j = m - 1; j >= 0; j--) {
      if (s[i][j] == '*') {
        if (c == -1) {
          c = 1;
        } else {
          c++;
        }
        r[i][j] = c;
      } else {
        c = -1;
        r[i][j] = 0;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int c = -1;
    for (int i = 0; i < n; i++) {
      if (s[i][j] == '*') {
        if (c == -1) {
          c = 1;
        } else {
          c++;
        }
        u[i][j] = c;
      } else {
        c = -1;
        u[i][j] = 0;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int c = -1;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i][j] == '*') {
        if (c == -1) {
          c = 1;
        } else {
          c++;
        }
        d[i][j] = c;
      } else {
        c = -1;
        d[i][j] = 0;
      }
    }
  }
  memset(an, 0, sizeof an);
  memset(ans, 0, sizeof ans);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int z = min(u[i][j], min(d[i][j], min(l[i][j], r[i][j])));
      if (z > 1) {
        an[i - z + 1][j]++;
        an[i + z][j]--;
        ans[i][j - z + 1]++;
        ans[i][j + z]--;
        v.push_back({i, {j, z - 1}});
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      ans[i][j] += ans[i][j - 1];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++) {
      an[i][j] += an[i - 1][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans[i][j] += an[i][j];
      if (s[i][j] == '*' && ans[i][j] == 0) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << v.size() << endl;
  for (auto it : v) {
    cout << it.first + 1 << " " << it.second.first + 1 << " "
         << it.second.second << endl;
  }
  return 0;
}
