#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int n, m;
int len1[1005][1005][4];
int len2[1005][1005];
bool vis[1005][1005];
vector<string> mp;
int main() {
  cin >> n >> m;
  mp.clear();
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    mp.push_back(s);
  }
  memset(len1, 0, sizeof(len1));
  memset(len2, 0, sizeof(len2));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mp[i][j] == '.')
        len1[i][j][2] = 0;
      else
        len1[i][j][2] = (j == 0 ? 1 : len1[i][j - 1][2] + 1);
    }
    for (int j = m - 1; j >= 0; --j) {
      if (mp[i][j] == '.')
        len1[i][j][3] = 0;
      else
        len1[i][j][3] = (j == m - 1 ? 1 : len1[i][j + 1][3] + 1);
    }
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i) {
      if (mp[i][j] == '*')
        len1[i][j][0] = (i == 0 ? 1 : len1[i - 1][j][0] + 1);
      else
        len1[i][j][0] = 0;
    }
    for (int i = n - 1; i >= 0; --i) {
      if (mp[i][j] == '*')
        len1[i][j][1] = (i == n - 1 ? 1 : len1[i + 1][j][1] + 1);
      else
        len1[i][j][1] = 0;
    }
  }
  int tot = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mp[i][j] == '*') {
        int x = min(len1[i][j][0], len1[i][j][1]);
        int y = min(len1[i][j][2], len1[i][j][3]);
        x = min(x, y);
        len2[i][j] = x - 1;
        if (len2[i][j] > 0) tot++;
      }
    }
  }
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < n; ++i) {
    set<int> ss;
    ss.clear();
    for (int j = 0; j < m; ++j) {
      if (mp[i][j] == '*' && len2[i][j]) {
        ss.insert(j + len2[i][j]);
      }
      while (!ss.empty() && (*ss.begin()) < j) {
        ss.erase(ss.begin());
      }
      if (!ss.empty()) vis[i][j] = true;
    }
    ss.clear();
    for (int j = m - 1; j >= 0; --j) {
      if (mp[i][j] == '*' && len2[i][j]) {
        ss.insert(j - len2[i][j]);
      }
      while (!ss.empty() && (*ss.begin()) > j) {
        ss.erase(ss.begin());
      }
      if (!ss.empty()) vis[i][j] = true;
    }
  }
  for (int j = 0; j < m; ++j) {
    set<int> ss;
    ss.clear();
    for (int i = 0; i < n; ++i) {
      if (mp[i][j] == '*' && len2[i][j]) {
        ss.insert(i + len2[i][j]);
      }
      while (!ss.empty() && (*ss.begin()) < i) {
        ss.erase(ss.begin());
      }
      if (!ss.empty()) vis[i][j] = true;
    }
    ss.clear();
    for (int i = n - 1; i >= 0; --i) {
      if (mp[i][j] == '*' && len2[i][j]) {
        ss.insert(i - len2[i][j]);
      }
      while (!ss.empty() && (*ss.begin()) > i) {
        ss.erase(ss.begin());
      }
      if (!ss.empty()) vis[i][j] = true;
    }
  }
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mp[i][j] == '*' && !vis[i][j]) {
        ok = false;
      }
    }
  }
  if (!ok)
    cout << -1 << endl;
  else {
    cout << tot << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (mp[i][j] == '*' && len2[i][j]) {
          printf("%d %d %d\n", i + 1, j + 1, len2[i][j]);
        }
      }
    }
  }
  return 0;
}
