#include <bits/stdc++.h>
using namespace std::chrono;
using namespace std;
inline int getint() {
  char c = getchar();
  int x = 0, minus = 1;
  while (c != EOF && c != '-' && !isdigit(c)) c = getchar();
  if (c == '-') {
    minus = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * minus;
}
inline long long getll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline double getdb() {
  static double x;
  scanf("%lf", &x);
  return x;
}
template <typename T>
void updmax(T& a, T const& b) {
  a = max(a, b);
}
template <typename T>
void updmin(T& a, T const& b) {
  a = min(a, b);
}
template <typename T>
int Descr(T* from, T* to) {
  sort(from, to);
  return (int)(unique(from, to) - from);
}
template <typename T>
int LBound(T* from, T* to, T const& val) {
  return (int)(lower_bound(from, to, val) - from);
}
template <typename T>
int UBound(T* from, T* to, T const& val) {
  return (int)(upper_bound(from, to, val) - from);
}
time_point<system_clock> timing;
void TimingBegin() { timing = system_clock::now(); }
void TimingEnd(const char* c = "time:") {
  auto end = system_clock::now();
  auto d = duration_cast<microseconds>(end - timing);
  printf("%s %.10f\n", c,
         double(d.count()) * microseconds::period::num /
             microseconds::period::den);
}
void TimingTick(const char* c = "time:") {
  TimingEnd(c);
  TimingBegin();
}
const int mxn = 1050;
int n, m;
char c[mxn][mxn];
enum { L = 0, R = 1, B = 2, T = 3 };
short v[4][mxn][mxn];
bool im[mxn][mxn];
int dst[mxn][mxn];
int lc[mxn];
int main() {
  n = getint();
  m = getint();
  for (int i = 0, lim__lim = (n + 1); i <= lim__lim; i++)
    for (int j = 0, lim__lim = (m + 1); j <= lim__lim; j++) im[i][j] = false;
  for (int i = 1, lim__lim = (n); i <= lim__lim; i++) scanf("%s", c[i] + 1);
  for (int i = 1, lim__lim = (m + 1); i <= lim__lim; i++) c[n + 1][i] = 0;
  for (int i = 1, lim__lim = (n); i <= lim__lim; i++)
    for (int j = 1, lim__lim = (m); j <= lim__lim; j++)
      v[L][i][j] = c[i][j] == '*' ? v[L][i][j - 1] + 1 : 0;
  for (int i = 1, lim__lim = (n); i <= lim__lim; i++)
    for (int j = m, lim__lim = (1); j >= lim__lim; j--)
      v[R][i][j] = c[i][j] == '*' ? v[R][i][j + 1] + 1 : 0;
  for (int i = n, lim__lim = (1); i >= lim__lim; i--)
    for (int j = 1, lim__lim = (m); j <= lim__lim; j++)
      v[B][i][j] = c[i][j] == '*' ? v[B][i + 1][j] + 1 : 0;
  for (int i = 1, lim__lim = (n); i <= lim__lim; i++)
    for (int j = 1, lim__lim = (m); j <= lim__lim; j++)
      v[T][i][j] = c[i][j] == '*' ? v[T][i - 1][j] + 1 : 0;
  for (int i = 1, lim__lim = (n); i <= lim__lim; i++)
    for (int j = 1, lim__lim = (m); j <= lim__lim; j++)
      dst[i][j] =
          min(min(v[L][i][j], v[R][i][j]), min(v[B][i][j], v[T][i][j])) - 1;
  for (int i = 1, lim__lim = (n); i <= lim__lim; i++) {
    memset(lc, 0, sizeof(int) * (m + 2));
    for (int j = 1, lim__lim = (m); j <= lim__lim; j++) {
      if (dst[i][j] <= 0) continue;
      lc[j - dst[i][j]]++;
      lc[j + dst[i][j] + 1]--;
    }
    int s = 0;
    for (int j = 1, lim__lim = (m); j <= lim__lim; j++) {
      s += lc[j];
      if (s != 0) im[i][j] = true;
    }
  }
  for (int j = 1, lim__lim = (m); j <= lim__lim; j++) {
    memset(lc, 0, sizeof(int) * (n + 2));
    for (int i = 1, lim__lim = (n); i <= lim__lim; i++) {
      if (dst[i][j] <= 0) continue;
      lc[i - dst[i][j]]++;
      lc[i + dst[i][j] + 1]--;
    }
    int s = 0;
    for (int i = 1, lim__lim = (n); i <= lim__lim; i++) {
      s += lc[i];
      if (s != 0) im[i][j] = true;
    }
  }
  bool able = true;
  for (int i = 1, lim__lim = (n); i <= lim__lim; i++)
    for (int j = 1, lim__lim = (m); j <= lim__lim; j++) {
      if (c[i][j] == '*' && !im[i][j]) {
        able = false;
      }
    }
  if (!able)
    printf("-1\n");
  else {
    int cnt = 0;
    for (int i = 1, lim__lim = (n); i <= lim__lim; i++)
      for (int j = 1, lim__lim = (m); j <= lim__lim; j++)
        if (dst[i][j] > 0) cnt++;
    printf("%d\n", cnt);
    for (int i = 1, lim__lim = (n); i <= lim__lim; i++)
      for (int j = 1, lim__lim = (m); j <= lim__lim; j++)
        if (dst[i][j] > 0) {
          printf("%d %d %d\n", i, j, dst[i][j]);
        }
  }
  return 0;
}
