#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 1e3 + 10;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
inline int ab(int x) { return x < 0 ? -x : x; }
inline int mm(int x, int p) { return x >= p ? x - p : x < 0 ? x + p : x; }
char mp[N][N];
int dp[4][N][N];
int vis[2][N][N];
vector<pair<pair<int, int>, int> > ans;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (mp[i][j] == '*')
        dp[0][i][j] = dp[0][i - 1][j] + 1, dp[2][i][j] = dp[2][i][j - 1] + 1;
      else
        dp[0][i][j] = 0, dp[2][i][j] = 0;
  for (int i = n; i >= 1; --i)
    for (int j = m; j >= 1; --j)
      if (mp[i][j] == '*')
        dp[1][i][j] = dp[1][i + 1][j] + 1, dp[3][i][j] = dp[3][i][j + 1] + 1;
      else
        dp[1][i][j] = 0, dp[3][i][j] = 0;
  for (int i = 1, tmp; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      tmp =
          min(min(dp[0][i][j], dp[1][i][j]), min(dp[2][i][j], dp[3][i][j])) - 1;
      if (tmp > 0) {
        ans.push_back({{i, j}, tmp});
        vis[0][i][j - tmp]++;
        vis[0][i][j + tmp + 1]--;
        vis[1][i - tmp][j]++;
        vis[1][i + tmp + 1][j]--;
      }
    }
  }
  bool flag = true;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      vis[0][i][j] += vis[0][i][j - 1];
      vis[1][i][j] += vis[1][i - 1][j];
      if (mp[i][j] == '*' && (vis[0][i][j] + vis[1][i][j]) == 0) flag = false;
    }
  }
  if (flag) {
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); ++i) {
      printf("%d %d %d\n", ans[i].first.first, ans[i].first.second,
             ans[i].second);
    }
  } else
    puts("-1");
  return 0;
}
