#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, z;
};
vector<node> ans;
int a[1010][1010], c[1010][1010], d[1010][1010];
int w[4][1002][1002];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    char x[1010];
    cin >> x + 1;
    for (int j = 1; j <= m; j++) a[i][j] = (x[j] == '*');
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (!a[i][j])
        w[0][i][j] = j;
      else
        w[0][i][j] = w[0][i][j - 1];
    for (int j = m + 1; j; j--)
      if (!a[i][j])
        w[1][i][j] = j;
      else
        w[1][i][j] = w[1][i][j + 1];
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++)
      if (!a[i][j])
        w[2][i][j] = i;
      else
        w[2][i][j] = w[2][i - 1][j];
    for (int i = n + 1; i; i--)
      if (!a[i][j])
        w[3][i][j] = i;
      else
        w[3][i][j] = w[3][i + 1][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j]) {
        int t = 10010;
        t = min(t, j - w[0][i][j]);
        t = min(t, w[1][i][j] - j);
        t = min(t, i - w[2][i][j]);
        t = min(t, w[3][i][j] - i);
        t--;
        if (t) {
          ans.push_back(node{i, j, t});
          c[i][j - t]++;
          c[i][j + t + 1]--;
          d[i - t][j]++;
          d[i + t + 1][j]--;
        }
      }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) c[i][j] += c[i][j - 1];
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++) d[i][j] += d[i - 1][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] && !c[i][j] && !d[i][j]) {
        cout << "-1";
        return 0;
      }
  cout << ans.size() << endl;
  for (auto i : ans) cout << i.x << ' ' << i.y << ' ' << i.z << endl;
  {}
  return 0;
}
