#include <bits/stdc++.h>   using namespace std;   template <class T>   typename T::value_type arr_sum(const T& v, int n) {     typename T::value_type sum = 0;     for (int i = 0; i < n; ++i) sum += v[i];     return sum;   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   int n, m;   vector<string> w(n);   void print_square(int x1, int x2, int y1, int y2) {     for (int i = x1; i < x2 + 1; ++i) {       if (w[i][y1] !=  w ) {         w[i][y1] =  + ;       }       if (w[i][y2] !=  w ) {         w[i][y2] =  + ;       }     }     for (int i = y1; i < y2 + 1; ++i) {       if (w[x1][i] !=  w ) {         w[x1][i] =  + ;       }       if (w[x2][i] !=  w ) {         w[x2][i] =  + ;       }     }     for (auto i : w) {       cout << i <<   n ;     }     exit(0);   }   void check1(vector<pair<int, int> >& v) {     int max1 = -1, min1 = 100001;     int max2 = -1, min2 = 100001;     for (int i = 0; i < v.size(); ++i) {       max1 = max(max1, v[i].first);       min1 = min(min1, v[i].first);       max2 = max(max2, v[i].second);       min2 = min(min2, v[i].second);     }     int left = 0, up = 0, right = 0, down = 0;     for (int i = 0; i < v.size(); ++i) {       if (v[i].first == min1 && min2 < v[i].second && v[i].second < max2) {         up = 1;       }       if (v[i].first == max1 && min2 < v[i].second && v[i].second < max2) {         down = 1;       }       if (v[i].second == min2 && min1 < v[i].first && v[i].first < max1) {         left = 1;       }       if (v[i].second == max2 && min1 < v[i].first && v[i].first < max1) {         right = 1;       }       if (min1 < v[i].first && v[i].first < max1 && min2 < v[i].second &&           v[i].second < max2) {         cout << -1;         exit(0);       }     }     if (max1 == min1) {       up = 0;       down = 0;     }     if (min2 == max2) {       left = 0;       right = 0;     }     if (max1 - min1 == max2 - min2) {       print_square(min1, max1, min2, max2);     }     if (up && down && left && right) {       cout << -1;       exit(0);     }     int diff = (max1 - min1) - (max2 - min2);     if (diff > 0) {       if (!left && max2 + (min1 - max1) >= 0) {         print_square(min1, max1, max2 + (min1 - max1), max2);       }       if (!right && min2 + (max1 - min1) < m) {         print_square(min1, max1, min2, min2 + (max1 - min1));       }       if (!left && !right && max1 - min1 < m) {         print_square(min1, max1, 0, max1 - min1);       }     }     if (diff < 0) {       if (!up && max1 + (min2 - max2) >= 0) {         print_square(max1 + (min2 - max2), max1, min2, max2);       }       if (!down && min1 + (max2 - min2) < n) {         print_square(min1, min1 + (max2 - min2), min2, max2);       }       if (!up && !down && max2 - min2 < n) {         print_square(0, max2 - min2, min2, max2);       }     }     cout << -1;     exit(0);   }   int main() {     cin >> n >> m;     vector<pair<int, int> > v;     for (int i = 0; i < n; ++i) {       string t;       cin >> t;       w.push_back(t);       for (int j = 0; j < m; ++j) {         if (t[j] ==  w ) {           v.push_back({i, j});         }       }     }     check1(v);   }   