#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> ans;
vector<vector<char>> a;
vector<vector<bool>> vis;
bool overlap(vector<int>& a, vector<int>& b) {
  int l = max(a[0], b[0]), r = min(a[1], b[1]);
  return l <= r;
}
bool helper(int i, int j, int k) {
  if (j - k < 0 || j + k >= m || i - k < 0 || i + k >= n) return false;
  if (a[i][j - k] != '*' || a[i][j + k] != '*' || a[i - k][j] != '*' ||
      a[i + k][j] != '*')
    return false;
  vis[i][j - k] = vis[i][j + k] = vis[i - k][j] = vis[i + k][j] = true;
  return true;
}
void merge(vector<vector<int>>& intervals) {
  int n = (int)((intervals).size());
  sort((intervals).begin(), (intervals).end());
  vector<vector<int>> merged;
  int i = 0;
  while (i < (int)((intervals).size())) {
    int j = i, l = intervals[i][0], r = intervals[i][1];
    while (j < (int)((intervals).size()) &&
           overlap(intervals[i], intervals[j])) {
      l = min(l, intervals[j][0]);
      r = max(r, intervals[j][1]);
      ++j;
    }
    merged.push_back({l, r});
    i = j;
  }
  intervals = merged;
}
bool solve() {
  int i, j;
  cin >> n >> m;
  a = vector<vector<char>>(n, vector<char>(m));
  vis = vector<vector<bool>>(n, vector<bool>(m, false));
  for (i = (0); i < (n); i++)
    for (j = (0); j < (m); j++) cin >> a[i][j];
  vector<vector<int>> h = vector<vector<int>>(n, vector<int>(m, 0)),
                      v = vector<vector<int>>(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i) {
    int j = 0;
    while (j < m) {
      if (a[i][j] != '*') {
        ++j;
        continue;
      }
      int k = j;
      while (k < m && a[i][k] == '*') {
        ++k;
      }
      for (int temp = j; temp < k; ++temp) {
        h[i][temp] = min(temp - j, k - 1 - temp);
      }
      j = k;
    }
  }
  for (int j = 0; j < m; ++j) {
    int i = 0;
    while (i < n) {
      if (a[i][j] != '*') {
        ++i;
        continue;
      }
      int k = i;
      while (k < n && a[k][j] == '*') {
        ++k;
      }
      for (int temp = i; temp < k; ++temp) {
        v[temp][j] = min(temp - i, k - 1 - temp);
      }
      i = k;
    }
  }
  vector<vector<vector<int>>> rows(n), cols(m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int k = min(h[i][j], v[i][j]);
      if (k) {
        rows[i].push_back({j - k, j + k});
        cols[j].push_back({i - k, i + k});
        ans.push_back({i + 1, j + 1, k});
      }
    }
  }
  for (int i = 0; i < n; ++i) merge(rows[i]);
  for (int j = 0; j < m; ++j) merge(cols[j]);
  for (int i = 0; i < n; ++i) {
    for (auto interval : rows[i]) {
      for (int j = interval[0]; j <= interval[1]; ++j) vis[i][j] = true;
    }
  }
  for (int j = 0; j < m; ++j) {
    for (auto interval : cols[j]) {
      for (int i = interval[0]; i <= interval[1]; ++i) vis[i][j] = true;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '*' && !vis[i][j]) return false;
    }
  }
  return true;
}
int main(int argc, char const* argv[]) {
  int t = 1;
  while (t--) {
    if (!solve()) {
      cout << -1 << '\n';
    } else {
      cout << (int)((ans).size()) << '\n';
      for (auto p : ans) cout << p[0] << " " << p[1] << " " << p[2] << '\n';
    }
    cout << '\n';
  }
  return 0;
}
