#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 100005;
const double PI = 4 * atan(1);
const long long MAX = 9223372036854775807;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; }
bool isprime(long long u) {
  for (long long i = 2; i <= (int)sqrt(u); i++) {
    if (u % i == 0) return 0;
  }
  return 1;
}
long long mod(long long to_mod) {
  to_mod %= MOD;
  while (to_mod < 0) to_mod += MOD;
  return to_mod % MOD;
}
long long moduloMultiplication(long long a, long long b, long long mod) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long n, k, m, ans, res, ss;
vector<pair<pair<long long, long long>, long long> > v;
char grid[1005][1005];
long long tabx1[1005][1005];
long long tabx2[1005][1005];
long long taby1[1005][1005];
long long taby2[1005][1005];
int vis[1005][1005][2][2];
string ch, ch1;
int main() {
  ios_base::sync_with_stdio(false);
  memset(vis, 0, sizeof(vis));
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j == 0) {
        tabx1[i][j] = (grid[i][j] == '*');
      } else {
        if (grid[i][j] == '*')
          tabx1[i][j] = tabx1[i][j - 1] + (grid[i][j] == '*');
        else
          tabx1[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      if (j == m - 1) {
        tabx2[i][j] = (grid[i][j] == '*');
      } else {
        if (grid[i][j] == '*')
          tabx2[i][j] = tabx2[i][j + 1] + (grid[i][j] == '*');
        else
          tabx2[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (j == 0) {
        taby1[j][i] = (grid[j][i] == '*');
      } else {
        if ((grid[j][i] == '*'))
          taby1[j][i] = taby1[j - 1][i] + (grid[j][i] == '*');
        else
          taby1[j][i] = 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = n - 1; j >= 0; j--) {
      if (j == n - 1) {
        taby2[j][i] = (grid[j][i] == '*');
      } else {
        if (grid[j][i] == '*')
          taby2[j][i] = taby2[j + 1][i] + (grid[j][i] == '*');
        else
          taby2[j][i] = 0;
      }
    }
  }
  ans = 0;
  ans = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      if (grid[i][j] == '*') {
        long long a = min(min(tabx1[i][j - 1], tabx2[i][j + 1]),
                          min(taby1[i - 1][j], taby2[i + 1][j]));
        if (a <= 0) continue;
        ans++;
        v.push_back(make_pair(make_pair(i, j), a));
        vis[i + a][j][0][1]++;
        vis[i - a][j][0][0]++;
        vis[i][j + a][1][1]++;
        vis[i][j - a][1][0]++;
      }
    }
  }
  long long a = 0;
  memset(tabx1, 0, sizeof(tabx1));
  for (int i = 0; i < n; i++) {
    a = 0;
    for (int j = 0; j < m; j++) {
      if (vis[i][j][1][0]) a += vis[i][j][1][0];
      if (grid[i][j] == '*' && a > 0) tabx1[i][j] = 1;
      if (vis[i][j][1][1]) a -= vis[i][j][1][1];
    }
  }
  a = 0;
  for (int i = 0; i < m; i++) {
    a = 0;
    for (int j = 0; j < n; j++) {
      if (vis[j][i][0][0]) a += vis[j][i][0][0];
      if (grid[j][i] == '*' && a > 0) tabx1[j][i] = 1;
      if (vis[j][i][0][1]) a -= vis[j][i][0][1];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*' && tabx1[i][j] == 0) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << ans << endl;
  for (auto t : v) {
    printf("%lld %lld %lld\n", t.first.first + 1, t.first.second + 1, t.second);
  }
  return 0;
}
