#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
int n, m;
char grid[1005][1005];
int mark[1005][1005], up[1005][1005], down[1005][1005], lt[1005][1005],
    rt[1005][1005];
int verti[1005][1005], hori[1005][1005];
vector<int> x, y, s;
void calcup() {
  for (long long i = 1; i <= (n); ++i) {
    for (long long j = 1; j <= (m); ++j) {
      if (grid[i][j] == '*') {
        up[i][j] = 1 + up[i - 1][j];
      } else {
        up[i][j] = 0;
      }
    }
  }
}
void calcdown() {
  for (long long i = n; i >= (1); --i) {
    for (long long j = 1; j <= (m); ++j) {
      if (grid[i][j] == '*') {
        down[i][j] = 1 + down[i + 1][j];
      } else {
        down[i][j] = 0;
      }
    }
  }
}
void calclt() {
  for (long long i = 1; i <= (n); ++i) {
    for (long long j = 1; j <= (m); ++j) {
      if (grid[i][j] == '*') {
        lt[i][j] = 1 + lt[i][j - 1];
      } else {
        lt[i][j] = 0;
      }
    }
  }
}
void calcrt() {
  for (long long i = 1; i <= (n); ++i) {
    for (long long j = m; j >= (1); --j) {
      if (grid[i][j] == '*') {
        rt[i][j] = 1 + rt[i][j + 1];
      } else {
        rt[i][j] = 0;
      }
    }
  }
}
bool check() {
  for (long long i = 1; i <= (n); ++i) {
    for (long long j = 1; j <= (m); ++j) {
      verti[i][j] += verti[i - 1][j];
      if (verti[i][j] > 0) mark[i][j] = 1;
    }
  }
  for (long long j = 1; j <= (m); ++j) {
    for (long long i = 1; i <= (n); ++i) {
      hori[i][j] += hori[i][j - 1];
      if (hori[i][j] > 0) mark[i][j] = 1;
    }
  }
  for (long long i = 1; i <= (n); ++i) {
    for (long long j = 1; j <= (m); ++j) {
      if (mark[i][j] == 0 && grid[i][j] == '*') {
        return false;
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 1; i <= (n); ++i) {
    for (long long j = 1; j <= (m); ++j) {
      cin >> grid[i][j];
    }
  }
  calcup();
  calcdown();
  calclt();
  calcrt();
  for (long long i = 1; i <= (n); ++i) {
    for (long long j = 1; j <= (m); ++j) {
      int vert = min(up[i][j], down[i][j]);
      int hor = min(lt[i][j], rt[i][j]);
      int cur = min(vert, hor);
      cur -= 1;
      if (cur <= 0) continue;
      verti[i - cur][j] += 1;
      verti[i + cur + 1][j] -= 1;
      hori[i][j - cur] += 1;
      hori[i][j + cur + 1] -= 1;
      x.push_back(i);
      y.push_back(j);
      s.push_back(cur);
    }
  }
  if (check()) {
    int sz = x.size();
    cout << sz << '\n';
    for (int i = 0; i < sz; i++) {
      cout << x[i] << " " << y[i] << " " << s[i] << '\n';
    }
    return 0;
  } else {
    cout << "-1\n";
    return 0;
  }
}
