#include <bits/stdc++.h>
using namespace std;
long long h, w;
long long d1[1010][1010];
long long d2[1010][1010];
long long dx1[1010][1010];
long long dx2[1010][1010];
long long dy1[1010][1010];
long long dy2[1010][1010];
long long ax[1010][1010];
long long ay[1010][1010];
int main(void) {
  long long dy[4] = {-1, 0, 0, 1};
  long long dx[4] = {0, -1, 1, 0};
  memset((d1), (0), sizeof(d1));
  memset((d2), (0), sizeof(d2));
  memset((ax), (0), sizeof(ax));
  memset((ay), (0), sizeof(ay));
  cin >> h >> w;
  vector<string> vs;
  vector<string> vd;
  for (long long y = (0); y < (h); ++y) {
    string s;
    cin >> s;
    for (long long x = (0); x < (w); ++x) {
      if (s[x] == '*') {
        d1[y + 1][x + 1] = 1;
        dx1[y + 1][x + 1] = 1;
        dx2[y + 1][x + 1] = 1;
        dy1[y + 1][x + 1] = 1;
        dy2[y + 1][x + 1] = 1;
      }
    }
  }
  for (long long y = (0); y < (1010); ++y) {
    for (long long x = (1); x < (1005); ++x) {
      if (dx1[y][x] == 1) {
        dx1[y][x] = dx1[y][x - 1] + dx1[y][x];
      }
    }
    for (long long x = (1005 - 1); x >= (0); --x) {
      if (dx2[y][x] == 1) {
        dx2[y][x] = dx2[y][x + 1] + dx2[y][x];
      }
    }
  }
  for (long long x = (0); x < (1010); ++x) {
    for (long long y = (1); y < (1005); ++y) {
      if (dy1[y][x] == 1) {
        dy1[y][x] = dy1[y - 1][x] + dy1[y][x];
      }
    }
    for (long long y = (1005 - 1); y >= (0); --y) {
      if (dy2[y][x] == 1) {
        dy2[y][x] = dy2[y + 1][x] + dy2[y][x];
      }
    }
  }
  vector<pair<long long, pair<long long, long long> > > ans;
  for (long long y = (1); y < (1005); ++y) {
    for (long long x = (1); x < (1005); ++x) {
      long long mn = 100000000;
      mn = min(mn, dx1[y][x]);
      mn = min(mn, dx2[y][x]);
      mn = min(mn, dy1[y][x]);
      mn = min(mn, dy2[y][x]);
      mn--;
      if (mn > 0) {
        ans.push_back(make_pair(mn, make_pair(y, x)));
        ax[y][x - mn] += 1;
        ax[y][x + mn + 1] -= 1;
        ay[y - mn][x] += 1;
        ay[y + mn + 1][x] -= 1;
      }
    }
  }
  for (long long y = (0); y < (1005); ++y) {
    for (long long x = (1); x < (1005); ++x) {
      ax[y][x] = ax[y][x] + ax[y][x - 1];
    }
  }
  for (long long x = (0); x < (1005); ++x) {
    for (long long y = (1); y < (1005); ++y) {
      ay[y][x] = ay[y][x] + ay[y - 1][x];
    }
  }
  for (long long y = (0); y < (1005); ++y) {
    for (long long x = (0); x < (1005); ++x) {
      if (ax[y][x] > 0) d2[y][x] = 1;
      if (ay[y][x] > 0) d2[y][x] = 1;
    }
  }
  long long flag = 1;
  for (long long y = (0); y < (1005); ++y) {
    for (long long x = (0); x < (1005); ++x) {
      if (d1[y][x] != d2[y][x]) flag = 0;
    }
  }
  if (flag == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans.size() << endl;
  for (long long i = (0); i < (ans.size()); ++i) {
    cout << ans[i].second.first << " " << ans[i].second.second << " "
         << ans[i].first << endl;
  }
  return 0;
}
