#include <bits/stdc++.h>
using namespace std;
long long int em(long long int x, long long int Mod, long long int n) {
  if (n == 0)
    return 1ll;
  else if (n % 2 == 0)
    return em((x % Mod * x % Mod) % Mod, Mod, n / 2) % Mod;
  else
    return (x % Mod * em((x % Mod * x % Mod) % Mod, Mod, (n - 1) / 2)) % Mod;
}
long long int up[1003][1003], lft[1003][1003], dwn[1003][1003];
long long int rgt[1003][1003], reachv[1003][1003], reachh[1003][1003];
char ch[1003][1003];
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, i, j, k, l;
  cin >> n >> m;
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    for (long long int j = (long long int)0; j < (long long int)m; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == '*') {
        up[i][j] = lft[i][j] = dwn[i][j] = rgt[i][j] = 1;
      }
    }
  }
  for (long long int i = (long long int)1; i < (long long int)n; i++) {
    for (long long int j = (long long int)0; j < (long long int)m; j++) {
      if (ch[i][j] == '*') up[i][j] += up[i - 1][j];
    }
  }
  for (i = n - 2; i >= 0; i--) {
    for (long long int j = (long long int)0; j < (long long int)m; j++) {
      if (ch[i][j] == '*') {
        dwn[i][j] += dwn[i + 1][j];
      }
    }
  }
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    for (long long int j = (long long int)1; j < (long long int)m; j++) {
      if (ch[i][j] == '*') {
        lft[i][j] += lft[i][j - 1];
      }
    }
  }
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    for (j = m - 2; j >= 0; j--) {
      if (ch[i][j] == '*') rgt[i][j] += rgt[i][j + 1];
    }
  }
  vector<pair<pair<long long int, long long int>, long long int> > ans;
  for (i = 1; i <= n - 2; i++) {
    for (j = 1; j <= m - 2; j++) {
      if (ch[i][j] == '*') {
        long long int mini =
            min({up[i - 1][j], dwn[i + 1][j], lft[i][j - 1], rgt[i][j + 1]});
        if (mini != 0) {
          reachv[i - mini][j]++;
          reachh[i][j - mini]++;
          reachv[i + mini + 1][j]--;
          reachh[i][j + mini + 1]--;
          ans.push_back({{i, j}, mini});
        }
      }
    }
  }
  long long int flag = 0;
  for (long long int i = (long long int)0; i < (long long int)m; i++) {
    long long int su = 0;
    for (long long int j = (long long int)0; j < (long long int)n; j++) {
      su += reachv[j][i];
      if (ch[j][i] == '*') {
        if (su > 0)
          reachv[j][i] = 1;
        else
          reachv[j][i] = 0;
      }
    }
  }
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    long long int su = 0;
    for (long long int j = (long long int)0; j < (long long int)m; j++) {
      su += reachh[i][j];
      if (ch[i][j] == '*') {
        if (su <= 0 && reachv[i][j] == 0) {
          flag = 1;
          break;
        }
      }
    }
  }
  if (flag) {
    cout << "-1\n";
  } else {
    cout << ans.size() << "\n";
    sort(ans.begin(), ans.end());
    for (pair<pair<long long int, long long int>, long long int> y : ans) {
      cout << y.first.first + 1 << " " << y.first.second + 1 << " " << y.second
           << "\n";
    }
  }
}
