#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1005][1005], s1[1005][1005], s2[1005][1005], s3[1005][1005],
    s4[1005][1005];
vector<pair<long long, pair<long long, long long> > > res;
bool fre[1005][1005];
void trace(long long u, long long v, long long k) {
  fre[u][v] = true;
  for (int i = 1; i <= k; i++) fre[u - i][v] = true;
  for (int i = 1; i <= k; i++) fre[u + i][v] = true;
  for (int i = 1; i <= k; i++) fre[u][v - i] = true;
  for (int i = 1; i <= k; i++) fre[u][v + i] = true;
}
void check(long long u, long long v) {
  long long U = min(s1[u][v], s2[u][v]);
  long long V = min(s3[u][v], s4[u][v]);
  long long k = min(U, V) - 1;
  if (k == 0) return;
  k = min(k, min(n, m));
  res.push_back(pair<long long, pair<long long, long long> >(
      k, pair<long long, long long>(u, v)));
  trace(u, v, k);
}
int main() {
  memset(s1, 0, sizeof s1);
  memset(s2, 0, sizeof s2);
  memset(s3, 0, sizeof s3);
  memset(s4, 0, sizeof s4);
  bool bo = false;
  memset(fre, false, sizeof fre);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    char c;
    for (int j = 1; j <= m; j++) {
      cin >> c;
      if (c == '.')
        a[i][j] = 0, fre[i][j] = true;
      else
        a[i][j] = 1, bo = true;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == 0)
        s1[i][j] = 0;
      else
        s1[i][j] = s1[i][j - 1] + 1;
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      if (a[i][j] == 0)
        s2[i][j] = 0;
      else
        s2[i][j] = s2[i][j + 1] + 1;
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++)
      if (a[i][j] == 0)
        s3[i][j] = 0;
      else
        s3[i][j] = s3[i - 1][j] + 1;
  for (int j = 1; j <= m; j++)
    for (int i = n; i >= 1; i--)
      if (a[i][j] == 0)
        s4[i][j] = 0;
      else
        s4[i][j] = s4[i + 1][j] + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == 1) check(i, j);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (fre[i][j] == false && a[i][j] != 0) {
        cout << "-1";
        return 0;
      }
  cout << res.size() << "\n";
  for (int i = 0; i < res.size(); i++) {
    cout << res[i].second.first << " " << res[i].second.second << " "
         << res[i].first << "\n";
  }
  return 0;
}
