#include <bits/stdc++.h>
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 1e3 + 2, mod = 1e9 + 7;
vector<string> v;
int n, m, sf_row[M][M], sf_col[M][M], pr_row[M][M], pr_col[M][M];
int h[M][M], h1[M][M];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      string s;
      cin >> s;
      s = "#" + s;
      if (i == 1) v.push_back(s);
      v.push_back(s);
    }
    for (int i = 1; i <= n; i++) {
      int r = -1;
      for (int j = m; j >= 1; j--) {
        if (v[i][j] == '*' && r == -1) r = j;
        if (v[i][j] == '.') r = -1;
        sf_col[i][j] = r;
      }
      r = -1;
      for (int j = 1; j <= m; j++) {
        if (v[i][j] == '*' && r == -1) r = j;
        if (v[i][j] == '.') r = -1;
        pr_col[i][j] = r;
      }
    }
    for (int j = 1; j <= m; j++) {
      int r = -1;
      for (int i = n; i >= 1; i--) {
        if (v[i][j] == '*' && r == -1) r = i;
        if (v[i][j] == '.') r = -1;
        sf_row[i][j] = r;
      }
      r = -1;
      for (int i = 1; i <= n; i++) {
        if (v[i][j] == '*' && r == -1) r = i;
        if (v[i][j] == '.') r = -1;
        pr_row[i][j] = r;
      }
    }
    vector<pair<pair<int, int>, int>> s;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (v[i][j] == '*') {
          int cnt = min(min(sf_row[i][j] - i, sf_col[i][j] - j),
                        min(i - pr_row[i][j], j - pr_col[i][j]));
          if (cnt == 0) continue;
          s.push_back({{i, j}, cnt});
          h[i - cnt][j]++;
          h[i + cnt + 1][j]--;
          h1[i][j - cnt]++;
          h1[i][j + cnt + 1]--;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        h1[i][j] += h1[i][j - 1];
      }
    }
    for (int j = 1; j <= m; j++) {
      for (int i = 1; i <= n; i++) {
        h[i][j] += h[i - 1][j];
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (v[i][j] == '*' && h[i][j] == 0 && h1[i][j] == 0)
          return cout << -1, 0;
      }
    }
    cout << s.size() << "\n";
    for (int i = 0; i < s.size(); i++)
      cout << s[i].first.first << " " << s[i].first.second << " " << s[i].second
           << "\n";
  }
  return 0;
}
void PT(int a) { cout << a << "\n"; }
void PT1(int a) { cout << a << " "; }
