#include <bits/stdc++.h>
using namespace std;
long long int sqr(long long int x) { return x * x; }
inline long long int add(long long int a, long long int b) {
  long long int c = (a % 1000000007) + (b % 1000000007);
  if (c >= 1000000007) c -= 1000000007;
  return c;
}
inline long long int mul(long long int a, long long int b) {
  return ((a % 1000000007) * 1ll * (b % 1000000007)) % 1000000007;
}
inline long long int sub(long long int a, long long int b) {
  long long int c = (a % 1000000007) - (b % 1000000007);
  if (c < 0) c += 1000000007;
  return c;
}
const long long int nax = 300 * 1000 + 10;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (long long int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  vector<vector<long long int>> a(n, vector<long long int>(m, 0));
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      a[i][j] = (s[i][j] == '*');
    }
  }
  vector<pair<long long int, pair<long long int, long long int>>> ans;
  long long int left[n][m], right[n][m], up[n][m], down[n][m];
  memset(left, 0, sizeof(left)), memset(right, 0, sizeof(right)),
      memset(up, 0, sizeof(up)), memset(down, 0, sizeof(down));
  for (long long int j = 0; j < m; ++j) {
    up[0][j] = a[0][j];
  }
  for (long long int i = 1; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      if (a[i][j]) up[i][j] = a[i][j] + up[i - 1][j];
    }
  }
  for (long long int j = 0; j < m; ++j) {
    down[n - 1][j] = a[n - 1][j];
  }
  for (long long int i = n - 2; i >= 0; i--) {
    for (long long int j = 0; j < m; ++j) {
      if (a[i][j]) down[i][j] = a[i][j] + down[i + 1][j];
    }
  }
  for (long long int i = 0; i < n; ++i) {
    left[i][0] = a[i][0];
  }
  for (long long int j = 1; j < m; ++j) {
    for (long long int i = 0; i < n; ++i) {
      if (a[i][j]) left[i][j] = left[i][j - 1] + a[i][j];
    }
  }
  for (long long int i = 0; i < n; ++i) {
    right[i][m - 1] = a[i][m - 1];
  }
  for (long long int j = m - 2; j >= 0; j--) {
    for (long long int i = 0; i < n; ++i) {
      if (a[i][j]) right[i][j] = right[i][j + 1] + 1;
    }
  }
  long long int vis1[n + 1][m + 1], vis2[n + 1][m + 1];
  memset(vis1, 0, sizeof(vis1)), memset(vis2, 0, sizeof(vis2));
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      if (a[i][j]) {
        long long int mn = min({up[i][j], down[i][j], left[i][j], right[i][j]});
        long long int sz = mn - 1;
        if (sz == 0) continue;
        ans.push_back({mn - 1, {i + 1, j + 1}});
        vis1[i][j - sz]++;
        vis2[i - sz][j]++;
        vis1[i][j + sz + 1]--;
        vis2[i + sz + 1][j]--;
      }
    }
  }
  for (long long int i = 1; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      vis2[i][j] += vis2[i - 1][j];
    }
  }
  for (long long int j = 1; j < m; ++j) {
    for (long long int i = 0; i < n; ++i) {
      vis1[i][j] += vis1[i][j - 1];
    }
  }
  bool ok = 1;
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      if (a[i][j]) {
        if (vis1[i][j] == 0 && vis2[i][j] == 0) {
          ok = false;
          break;
        }
      }
    }
  }
  if (!ok) {
    cout << -1;
    return 0;
  }
  cout << ans.size() << "\n";
  for (long long int i = 0; i < ans.size(); ++i) {
    cout << ans[i].second.first << " " << ans[i].second.second << " "
         << ans[i].first << "\n";
  }
  return 0;
}
