#include<bits/stdc++.h>

using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input Output ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)

#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n';
#define yes cout << "YES" << '\n';
#define case cout << "Case " << t++ << ": ";

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a,pll b){ if(a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

/*** BitWise Operations
bool getBit (ll num, ll pos) { return num & (1 << pos); } // get bit right -> left
ll setBit (ll num, ll pos) { return num | (1 << pos); }
ll chearBit (ll num, ll pos) { ll mask = ~(1 << pos); return num & mask; }
ll updateBit (ll num, ll pos, bool bit1or0) { ll value = bit1or0 ? 1 : 0; ll mask = ~(1 << pos); return (num & mask) | (value << pos); }
 ***/

/*** Grids ***/
int drx[8] = {-2,-2,-1,-1,1,1,2,2};
int dcy[8] = {-1,1,-2,2,-2,2,-1,1};
int dirx[4] = { -1, 0, 1, 0 };
int diry[4] = { 0, -1, 0, 1 };

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }

 ***/
template <class T> inline T gcd(T a,T b){if(b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a,T b){return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b,T p){ll ans = 1;while(p--) ans *= b; return ans;}

bool check(string str)
{
    string temp = str;
    rev(temp);
    if(str == temp) return true;
    else return false;
}

int main() {

#ifndef ONLINE_JUDGE
    clock_t tStart = clock();
    //freopen("/opt/Coding/clion code/input.txt", "r", stdin);
    //freopen("/opt/Coding/clion code/output.txt", "w", stdout);
#endif

    ll n, m, num, nDigit, tc, t = 1;

    sc2(num, m);
    string str[num];
    bool used[num];
    mem(used, false);

    for (ll i = 0; i < num; ++i) {
        cin >> str[i];
    }

    vector<pair<string, string> > vp;
    //vector <string> sing;

    string ext = "";
    for (ll i = 0; i < num - 1; ++i) {
        for (ll j = i + 1; j < num; ++j) {
            if(!used[i] && !used[j]) {
                string temp = str[i];
                rev(temp);
                if(temp == str[j]) {
                    vp.pb(mp(str[i], str[j]));
                    used[i] = true;
                    used[j] = true;
                    break;
                }
            }
        }
        if(check(str[i]) && !used[i]) {
            ext = str[i];
            used[i] = true;
        }
    }
    if(check(str[num - 1]) && !used[num - 1]) {
        ext = str[num - 1];
        used[num - 1] = true;
    }

    string ans = "";
    for (ll i = 0; i < vp.size(); ++i) {
        ans += vp[i].first;
    }
    ans += ext;
    for (ll i = vp.size()- 1; i >= 0; i--) {
        ans += vp[i].second;
    }

    cout << ans.size() << endl;

    if(ans.size() != 0) {
        cout << ans << endl;
    }
    else
        cout << endl;

#ifndef ONLINE_JUDGE
    printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
#endif

}


#include<bits/stdc++.h>

using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input Output ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)

#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n';
#define yes cout << "YES" << '\n';
#define case cout << "Case " << t++ << ": ";

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a,pll b){ if(a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

/*** BitWise Operations
bool getBit (ll num, ll pos) { return num & (1 << pos); } // get bit right -> left
ll setBit (ll num, ll pos) { return num | (1 << pos); }
ll chearBit (ll num, ll pos) { ll mask = ~(1 << pos); return num & mask; }
ll updateBit (ll num, ll pos, bool bit1or0) { ll value = bit1or0 ? 1 : 0; ll mask = ~(1 << pos); return (num & mask) | (value << pos); }
 ***/

/*** Grids ***/
int drx[8] = {-2,-2,-1,-1,1,1,2,2};
int dcy[8] = {-1,1,-2,2,-2,2,-1,1};
int dirx[4] = { -1, 0, 1, 0 };
int diry[4] = { 0, -1, 0, 1 };

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }

 ***/
template <class T> inline T gcd(T a,T b){if(b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a,T b){return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b,T p){ll ans = 1;while(p--) ans *= b; return ans;}

bool check(string str)
{
    string temp = str;
    rev(temp);
    if(str == temp) return true;
    else return false;
}

int main() {

#ifndef ONLINE_JUDGE
    clock_t tStart = clock();
    //freopen("/opt/Coding/clion code/input.txt", "r", stdin);
    //freopen("/opt/Coding/clion code/output.txt", "w", stdout);
#endif

    ll n, m, num, nDigit, tc, t = 1;

    sc2(num, m);
    string str[num + 5], temp = "";
    bool used[num + 5];
    mem(used, false);

    for (ll i = 0; i < num; ++i) {
        cin >> str[i];
    }

    vector<pair<string, string> > vp;
    vector <string>  lef, righ;

    string ext = "";

    for (ll i = 0; i < num; ++i) {
        temp = str[i];
        rev(temp);
        for (ll j = 0; j < num; ++j) {
            if(i != j && temp == str[j] && !used[j]) {
                used[i] = true;
                used[j] = true;
                lef.pb(str[i]);
                righ.pb(str[j]);
            }
        }
    }

    for (ll i = 0; i < num; ++i) {
        if(!used[i]) {
            temp = str[i];
            rev(temp);
            if(temp == str[i]) {
                lef.pb(str[i]);
                break;
            }
        }
    }

    string ans = "";
    for (ll i = 0; i < lef.size(); ++i) {
        ans += lef[i];
    }
    for (ll i = righ.size()- 1; i >= 0; i--) {
        ans += righ[i];
    }

    cout << ans.size() << endl;

    if(ans.size() > 0) {
        cout << ans << endl;
    }

#ifndef ONLINE_JUDGE
    printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
#endif

}


<?php
list($n,$m)=explode(' ',rtrim(fgets(STDIN)));
$min_x=$min_y=100;
$max_x=$max_y=-1;
$letter=array();
for ($i=0;$i<$n;$i++) {
  $line=rtrim(fgets(STDIN));
  $letter[]=$line;
  for ($j=0;$j<$m;$j++) {
    if ($line[$j]=='*') {
      $min_x=min($min_x,$j);
      $min_y=min($min_y,$i);
      $max_x=max($max_x,$j);
      $max_y=max($max_y,$i);
    }
  }
}
for ($i=$min_y;$i<=$max_y;$i++) {
  for ($j=$min_x;$j<=$max_x;$j++) {
    echo $letter[$i][$j];
  }
  echo "\n";
}
?>


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft-1;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}
	echo substr($lines[$j], $i, $iLeft);

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for(;$j<=$y && isset($rows[$j]);$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
			$rightJ = $j;
			$rightI = $i;
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;

for($j = $leftJ;$j<$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft-1;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
var_dump($line);
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);
for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft = $x-$iLeft;
for($j=0;$j<$y && !isset($rows[$j]);$j++);
for(;$j<$y && isset($rows[$j]);$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

var_dump($lines);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;

			$rightJ = max($rightJ, $j);
			$rightI = max($rightI, $i);
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;
			$leftI = min($leftI, $i);
			$leftJ = min($leftJ, $j);

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;
for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft-1;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\r\n";
}
	echo substr($lines[$j], $i, $iLeft);

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
			$rightJ = $j;
			$rightI = $i;
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;

for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;

			$rightJ = max($rightJ, $j);
			$rightI = max($rightI, $i);
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;
			$leftI = min($leftI, $i);
			$leftJ = min($leftJ, $j);

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;
echo "$leftI $rightI, $leftJ $rightJ\n";
for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft;$j++){
	if (isset($rows[$j]))
		echo substr($lines[$j], $i, $iLeft) . "\n";
}

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
if ($i == $iLeft)
	$iLeft = 1;
else
	$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . PHP_EOL;
}

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);


<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightJ = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
			$rightJ = $j;
			$rightI = $i;
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;

		}
	}
}
for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}


<?php

$in = 'php://stdin';
//$in = 'input.txt';

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');
list($n, $m) = explode(' ', array_shift($arr));

while (!$arr[count($arr) - 1]) {
	array_pop($arr);
}

foreach ($arr as $k1 => &$valf) {
	$valf = trim($valf);
	$valf = str_split($valf);
	foreach ($valf as $k => $a) {
		$arr2[$k][$k1] = $a;
	}

}
foreach ($arr as $k => $val) {
	if (in_array('*', $val)) {
		$minx = isset($minx) ? $minx : $k;
		$maxx = $k;
	}
}

foreach ($arr2 as $k => $val) {
	if (in_array('*', $val)) {
		$miny = isset($miny) ? $miny : $k;
		$maxy = $k;
	}
}

for ($i = $minx; $i <= $maxx; $i++) {
	for ($j = $miny; $j <= $maxy; $j++) {
		echo $arr[$i][$j];
	}
	echo "\n";
}


<?php
function emptyColumn($j) {
	global $n, $s;
	for ($i = 0; $i < $n; $i++)
		if ($s[$i][$j] == '*')
			return false;
	return true;
}
function emptyRow($i) {
	global $m, $s;
	for ($j = 0; $j < $m; $j++)
		if ($s[$i][$j] == '*')
			return false;
	return true;
}

fscanf(STDIN, "%d %d", $n, $m);
$s = array();
for ($i = 0; $i < $n; $i++)
	$s[$i] = fgets(STDIN);
$li = 0; $ri = $n - 1;
$lj = 0; $rj = $m - 1;
while (emptyRow($li)) $li++;
while (emptyRow($ri)) $ri--;
while (emptyColumn($lj)) $lj++;
while (emptyColumn($rj)) $rj--;
for ($i = $li; $i <= $ri; $i++)
	print(substr($s[$i], $lj, $rj - $lj + 1)."\n")
?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    unset($array[$row]);
/*
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
*/
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

/*
foreach ($entries as $value) {
    $emptyRow = true;
        for ($i = 0; $i < strlen($value); $i++) {
            if ($value[$i] != 'x') {
            $emptyRow = false;
            echo($value[$i]);
            }
        }
    if (!$emptyRow) echo "\n";
}
*/

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
        else next($entries);
    }
    echo "\n";
}

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    unset($array[$row]);
/*
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
*/
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
 $emptyRow = true;
 for ($i = 0; $i < strlen($value); $i++) {
  if ($value[$i] != 'x') {$emptyRow = false; echo($value[$i]);}
 }
 if (!$emptyRow) echo "\n";
}

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$entries = array();
for ($i = 0; $i < $data[0]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    $emptyRow = true;
        for ($i = 0; $i < strlen($value); $i++) {
            if ($value[$i] != 'x') {
            $emptyRow = false;
            echo($value[$i]);
            }
        }
    if (!$emptyRow) echo "\n";
}

/*
foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
        else next($entries);
    }
    echo "\n";
}
*/

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}
//

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    unset($array[$row]);
/*
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
*/
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    $emptyRow = true;
        for ($i = 0; $i < strlen($value); $i++) {
            if ($value[$i] != 'x') {
            $emptyRow = false;
            echo($value[$i]);
            }
        }
    if (!$emptyRow) echo "\n";
}

/*
foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
        else next($entries);
    }
    echo "\n";
}
*/

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        unset($array[$i][$col]);
    }
    return $array;
}

function delete_row($array, $row) {
    unset($array[$row]);
/*
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
*/
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}

?>


<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}
print_r($entries);

?>


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
    fgetc(STDIN);
}
for ($i = $upper; $i <= $bottom; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
    }
}


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
//    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
    }
    echo "\n";
}


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
//        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
//        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
    fgetc(STDIN);
}
for ($i = $upper; $i <= $bottom; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
    }
    if ($i != $bottom) {
        echo "\n";
    }
}


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
//for ($i = 0; $i < $n; $i++) {
//    for ($j = 0; $j < $m; $j++) {
//        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
//            echo $pixels[$i][$j];
//        }
//        if ($j == $m - 1) {
//            echo "\n";
//        }
//    }
//}

print_r($pixels);


n,m=map(int,raw_input().split())
s=[raw_input() for i in xrange(n)]
x1,y1,x2,y2=n,m,0,0
for i in range(n):
	for j in range(m):
		if s[i][j]=='*':
			x1=min(x1,i)
			y1=min(y1,j)
			x2=max(x2,i)
			y2=max(y2,j)
for i in xrange(x1,x2+1):
	print s[i][y1:y2+1]


row,col = map(int,raw_input().split())
xr = xrange(row)
a = [raw_input() for _ in xr]
miny=maxx=maxy=0
minx=col
for y in xr:
    if a[y].find('*') > -1:
        miny = y
        break

maxy += miny
for y in xrange(miny,row):
    i = a[y].find('*')
    if i > -1:
        maxy += 1
        if i < minx:
            minx = i

        if y == miny:
            for x in xrange(col-1,0,-1):
                if a[y][x] == '*':
                    if x > maxx:
                        maxx = x
                        break
        else:
            for x in xrange(maxx,col):
                if a[y][x] == '*':
                    if x > maxx:
                        maxx = x
                        break

for y in xrange(miny,maxy):
    print a[y][minx:maxx+1]


row,col = map(int,raw_input().split())
xr = xrange(row)
a = [raw_input() for _ in xr]
miny=maxx=maxy=0
minx=col
for y in xr:
    if a[y].find('*') > -1:
        miny = y
        break

for y in xrange(miny,row):
    i = a[y].find('*')
    if i > -1:
        maxy = 0
        if i < minx:
            minx = i

        if y == miny:
            for x in xrange(col-1,0,-1):
                if a[y][x] == '*':
                    if x > maxx:
                        maxx = x
                        break
        else:
            for x in xrange(maxx,col):
                if a[y][x] == '*':
                    if x > maxx:
                        maxx = x
                        break
    else:
        maxy += 1
maxy = row - maxy

for y in xrange(miny,maxy):
    print a[y][minx:maxx+1]


n , m = map(int , input().split())
l=[]
lhs = 0
rhs=0
t=0
for i in range(n):
    temp = str(input())
    if t==1 or temp.count('.')!=len(temp):
        t=1
        l.append(temp)
        if '*' in temp:
            lhs = min(lhs , temp.index('*'))
            rhs = max(rhs , temp.rfind('*'))
t=0
x = l[::-1]
i=0
while t==0:
    if x[i] == m*'.':
        x.remove(x[i])
        i=i-1
    else:
        t=1
    i = i+1
ans = x[::-1]
for i in ans:
    print(i)


n , m = map(int , input().split())
l=[]
lhs = 0
rhs=0
for i in range(n):
    temp = str(input())
    if temp.count('.')!=len(temp):
        l.append(temp)
        lhs = max(lhs , temp.index('*'))
        rhs = max(rhs , temp.rfind('*'))
for i in l:
    print(i[lhs:rhs+1])


n , m = map(int , input().split())
l=[]
lhs = 0
rhs=0
t=0
for i in range(n):
    temp = str(input())
    if t==1 or temp.count('.')!=len(temp):
        t=1
        l.append(temp)
        if '*' in temp:
            lhs = max(lhs , temp.index('*'))
            rhs = max(rhs , temp.rfind('*'))
t=0
x = l[::-1]
i=0
while t==0:
    if x[i] == m*'.':
        x.remove(x[i])
        i=i-1
    else:
        t=1
    i = i+1
ans = x[::-1]
for i in ans:
    print(i[lhs:rhs+1])


n , m = map(int , input().split())
l=[]
lhs = m
rhs=0
t=0
for i in range(n):
    temp = str(input())
    if t==1 or temp.count('.')!=len(temp):
        t=1
        l.append(temp)
        if '*' in temp:
            lhs = min(lhs , temp.index('*'))
            rhs = max(rhs , temp.rfind('*'))
t=0
x = l[::-1]
i=0
while t==0:
    if x[i] == m*'.':
        x.remove(x[i])
        i=i-1
    else:
        t=1
    i = i+1
ans = x[::-1]
for i in ans:
    print(i[lhs:rhs+1])


n , m = map(int , input().split())
l=[]
lhs = 0
rhs=0
t=0
for i in range(n):
    temp = str(input())
    if t==1 or temp.count('.')!=len(temp):
        t=1
        l.append(temp)
        if '*' in temp:
            lhs = min(lhs , temp.index('*'))
            rhs = max(rhs , temp.rfind('*'))
t=0
x = l[::-1]
i=0
while t==0:
    if x[i] == m*'.':
        x.remove(x[i])
        i=i-1
    else:
        t=1
    i = i+1
ans = x[::-1]
for i in ans:
    print(i[lhs:rhs+1])


n = input()
r, c = n.split(' ')
r = int(r)
c = int(c)
f = ''
min = 0
mn = 51
mx = 0
max = 0
for i in range(0,r):
    e = input()
    f += e
    min = e.find('*')
    if min != -1:
        m = 2
        max = min
        while m > -1:
            m = e[max+1:].find('*')
            if m != -1:
                max = m + max + 1
    if min < mn and min != -1:
        mn = min
    if max > mx:
        mx = max
count = 0
for j in range(0,r):
    final = f[j*c:(j+1)*c]
    s = f[(j+1)*c:].find('*')
    if final.find('*') != -1:
        print(final[mn:mx+1])
        count += 1
    elif count != 0 and s != -1:
        print(final[mn:mx + 1])


n = input()
r, c = n.split(' ')
r = int(r)
c = int(c)
f = ''
min = 0
mn = 51
mx = 0
max = 0
for i in range(0,r):
    e = input()
    f += e
    min = e.find('*')
    if min != -1:
        m = 2
        max = min
        while m > -1:
            m = e[max+1:].find('*')
            if m != -1:
                max = m + max + 1
    if min < mn and min != -1:
        mn = min
    if max > mx:
        mx = max
for j in range(0,r):
    final = f[j*c:(j+1)*c]
    if final.find('*') != -1:
        print(final[mn:mx+1])


n,m=map(int,input().split())
L=[input() for x in range(n)]

p=10000000000
p1=-1
pp=100000000
pp1=-1
for i in range(n) :
    if L[i].count("*")>0 :
        p=min(p,i)
        p1=max(p1,i)
        pp=min(L[i].index("*"),pp)
        pp1=max(L[i].rindex("*"),pp1)

for i in range(p,p1+1) :
    print(L[i][pp:pp1+1])


n, m = list(map(int, input().split()))

arr = []

for _ in range(n):
    arr.append(input())

startRows = 0
for index, i in enumerate(arr):
    if('*' in i):
        startRows = index
        break

stopRows = n
for i in range(n-1, -1, -1):
    if('*' in arr[i]):
        stopRows = i
        break

startCols = m
for i in arr:
    if('*' in i and i.index('*') < startCols):
        startCols = i.index('*')

stopCols = 0
for i in arr:
    if('*' in i and i.rindex('*') > stopCols):
        stopCols = i.rindex('*')

for i in range(startRows, stopRows+1):
    for j in range(startCols, stopCols+1):
        print(arr[i][j], end='')
    print('')


n, m = list(map(int, input().split()))

arr = []

for _ in range(n):
    arr.append(input())

startRows = 0
for index, i in enumerate(arr):
    if('*' in i):
        startRows = index
        break

stopRows = n
for i in range(n-1, -1, -1):
    if('*' in arr[i]):
        stopRows = i
        break

startCols = m
for i in arr:
    if('*' in i and i.index('*') < startCols):
        startCols = i.index('*')

stopCols = 0
for i in arr:
    if('*' in i and i.rindex('*') > stopCols):
        stopCols = i.rindex('*')

print(f"start rows {startRows}, stop rows {stopRows}, start cols {startCols}, stop cols {stopCols}")

for i in range(startRows, stopRows+1):
    for j in range(startCols, stopCols+1):
        print(arr[i][j], end='')
    print('')


h, w = map(int, input().split())
pyoko = [False] * w
ptate = [False] * h
maze = []
for i in range(h):
    s = input()
    maze.append(s)
    if s.count("*") != 0:
        ptate[i] = True
    for j in range(w):
        if s[j] == "*":
            pyoko[j] = True
s
l, r = 0, w-1
while pyoko[l] != True:
    l += 1
while pyoko[r] != True:
    r -= 1
t,b = 0, h-1
while ptate[t] != True:
    t += 1
while ptate[b] != True:
    b -= 1

for i in range(t, b+1):
    print(maze[i][l:r+1])


n, m = list(map(int, input().split()))

lst = [list(input()) for i in range(n)]

a = []
b = []

for i in range(n):
    flag = True
    for j in lst[i]:
        if j == '*':
            flag = False
    if not flag:
        a.append(i)

for x in range(m):
    flag = True
    for i in lst:
        if i[x] == '*':
            flag = False
    if not flag:
        b.append(x)

# print(a, b)

tmp = a[-1] + 1
lst = lst[a[0]:tmp]

tmp = b[-1] + 1
for i in range(len(lst)):
    lst[i] = lst[i][b[0]:tmp]

for i in lst:
    print(''.join(i))


n, m = list(map(int, input().split()))

lst = [list(input()) for i in range(n)]

a = []
b = []

for i in range(n):
    flag = True
    for j in lst[i]:
        if j == '*':
            flag = False
    if not flag:
        a.append(i)

for x in range(m):
    flag = True
    for i in lst:
        if i[x] == '*':
            flag = False
    if not flag:
        b.append(x)

# print(a, b)

tmp = a[-1] + 1
lst = lst[a[0]:tmp]

tmp = b[-1] + 1
for i in range(len(lst)):
    lst[i] = lst[i][b[0]:tmp]

for i in lst:
    print(' '.join(i))


n, m = map(int,input().split())
table = [input() for i in range(n)]
v1,h1,v2,h2 = 51,51,0,0
for i in range(n):
    for j in range(m):
        if table[i][j] == "*":
            v1 = min(v1,j)
            v2 = max(v2,j)
            h1 = min(h1,i)
            h2 = max(h2,i)
for i in range(h1,h2+1):
    for j in range(v1,v2+1):
        print(table[i][j],end="")
    print()


X = list(map(int, input().split()))
Picture, FirstRow, LastRow, First, Last = [], X[0], 0, X[1], 0
for i in range(X[0]):
    Temp = input()
    Picture.append(Temp)
    if "*" in Temp:
        FirstRow = min(FirstRow, i)
        LastRow = i
        First = min(First, Temp.index("*"))
        Last = max(Last, X[1] - Temp[::-1].index("*"))
for i in range(FirstRow, LastRow + 1):
    print(Picture[i][First:Last])

# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Here in Bojnurd
# Caption: So Close man!! Take it easy!!!!
# CodeNumber: 646


X = list(map(int, input().split()))
Found = False
Answer = []
First, Last = 0, 0
for i in range(X[0]):
    Temp = input()
    if not Found:
        if "*" in Temp:
            First = Temp.index("*")
            Last = X[1] - Temp[::-1].index("*")
            Found = True
            Answer.append(Temp[First:Last])
    else:
        if "*" not in Temp:
            print(*Answer, sep="\n")
            exit()
        Answer.append(Temp[First:Last])
print(*Answer, sep="\n")

# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Here in Bojnurd
# Caption: So Close man!! Take it easy!!!!
# CodeNumber: 646


import sys
from array import array  # noqa: F401

def input():
    return sys.stdin.buffer.readline().decode('utf-8')

n, m = map(int, input().split())
a = [list(input().rstrip()) for _ in range(n)]

for i in range(n):
    if all(a[j][0] == '.' for j in range(n)):
        for j in range(n):
            a[j].pop(0)
    else:
        break
for i in range(n):
    if all(a[j][-1] == '.' for j in range(n)):
        for j in range(n):
            a[j].pop()
    else:
        break
for i in range(n):
    if '*' not in a[0]:
        a.pop(0)
    else:
        break
for i in range(n):
    if '*' not in a[-1]:
        a.pop()
    else:
        break

for row in a:
    print(*row, sep='')


import sys
from array import array  # noqa: F401

def input():
    return sys.stdin.buffer.readline().decode('utf-8')

n, m = map(int, input().split())
a = [list(input().rstrip()) for _ in range(n)]

while True:
    if all(a[j][0] == '.' for j in range(n)):
        for j in range(n):
            a[j].pop(0)
    else:
        break
while True:
    if all(a[j][-1] == '.' for j in range(n)):
        for j in range(n):
            a[j].pop()
    else:
        break
while True:
    if '*' not in a[0]:
        a.pop(0)
    else:
        break
while True:
    if '*' not in a[-1]:
        a.pop()
    else:
        break

for row in a:
    print(*row, sep='')


n, m = map(int, input().split())

l = [input() for i in range(n)]

l1 = [j for i in range(n) for j in range(m) if l[i][j] == '*']
l2 = [i for i in range(n) for j in range(m) if l[i][j] == '*']

mi1, ma1 = min(l1), max(l1)+1
mi2, ma2 = min(l2), max(l2)+1

for i in range(mi2, ma2):
    print(l[i][mi1:ma1])


n, m = map(int, input().split())

l = [input() for i in range(n)]
print(l)
l1 = [j for i in range(n) for j in range(m) if l[i][j] == '*']
l2 = [i for i in range(n) for j in range(m) if l[i][j] == '*']

mi1, ma1 = min(l1), max(l1)+1
mi2, ma2 = min(l2), max(l2)+1

for i in range(mi2, ma2):
    print(l[i][mi1:ma1])


n,m=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(input()))
for i in range(n):
    if '*' in a[i]:
        x=i
        break
a.reverse()
for i in range(n):
    if '*' in a[i]:
        y=n-i-1
        break
else:
    y=x
a.reverse()
b=[]
c=[]
for i in range(n):
    for j in range(m):
        if a[i][j]=='*':
            break
    b.append(j)
for i in range(n):
    j=m-1
    while j>=0:
        if a[i][j]=='*':
            break
        j-=1
    c.append(j)
for i in range(n):
    flag=0
    for j in range(m):
        if i>=x and i<=y and j>=min(b) and j<=max(c):
            print(a[i][j],end="")
            flag=1
    if flag==1:
        print()


n,m=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(input()))
for i in range(n):
    if '*' in a[i]:
        x=i
        break
a.reverse()
for i in range(n):
    if '*' in a[i]:
        y=n-i
        break
a.reverse()
b=[]
c=[]
for i in range(n):
    for j in range(m):
        if a[i][j]=='*':
            break
    b.append(j)
for i in range(n):
    j=m-1
    while j>=0:
        if a[i][j]=='*':
            break
        j-=1
    c.append(j)
for i in range(n):
    for j in range(m):
        if i>=x and i<=y and j>=min(b) and j<=max(c):
            print(a[i][j],end="")
    print()


n,m=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(input()))
for i in range(n):
    if '*' in a[i]:
        x=i
        break
a.reverse()
for i in range(n):
    if '*' in a[i]:
        y=n-i
        break
a.reverse()
b=[]
c=[]
for i in range(n):
    for j in range(m):
        if a[i][j]=='*':
            break
    b.append(j)
for i in range(n):
    j=m-1
    while j>=0:
        if a[i][j]=='*':
            break
        j-=1
    c.append(j)
for i in range(n):
    flag=0
    for j in range(m):
        if i>=x and i<=y and j>=min(b) and j<=max(c):
            print(a[i][j],end="")
            flag=1
    if flag==1:
        print()


n, m = map(int, input().split())
a = []
imin, imax = n - 1, 0
jmin, jmax = m - 1, 0
for i in range(n):
  s = input()
  a.append(s)
  for j in range(m):
    if s[j] == '*':
      imin = min(imin, i)
      imax = max(imax, i)
      jmin = min(jmin, j)
      jmax = max(jmax, j)

for i in range(imin, imax + 1):
  print(a[i][jmin:jmax+1])


n, m = map(int, input().split())
a = []
imin, imax = m - 1, 0
jmin, jmax = n - 1, 0
for i in range(n):
  s = input()
  a.append(s)
  for j in range(m):
    if s[j] == '*':
      imin = min(imin, i)
      imax = max(imax, i)
      jmin = min(jmin, j)
      jmax = max(jmax, j)

for i in range(imin, imax + 1):
  print(a[i][jmin:jmax+1])


n, m = map(int, input().split())
a = []
left, right = m - 1, 0
for _ in range(n):
  s = input()
  if s.count('*') > 0:
    a.append(s)
    left = min(left, s.index('*'))
    right = max(right, m - 1 - s[::-1].index('*'))
for s in a:
  print(s[left:right+1])


n, m = map(int, input().split())
a = []
left, right = m - 1, 0
for _ in range(n):
  s = input()
  if s.count('*') > 0:
    a.append(s)
    left = min(left, s.index('*'))
    right = max(right, n - s[::-1].index('*'))
for s in a:
  print(s[left:right+1])


n, m = map(int, input().split())
a = []
left, right = m - 1, 0
first_row, last_row = n - 1, 0
for i in range(n):
  s = input()
  a.append(s)
  if s.count('*') > 0:
    first_row = min(first_row, i)
    last_row = max(last_row, i)
    left = min(left, s.index('*'))
    right = max(right, m - 1 - s[::-1].index('*'))
for i in range(first_row, last_row + 1):
  print(a[i][left:right+1])


n,m = map(int,input().split())
a = []
x = []
y = []
for i in range(n):
    b = list(input())
    if "*" in b:
        x.append(i)
        j = 0
        while b[j] == "." and j < m: j += 1
        y.append(j)
        j = m-1
        while b[j] == "." and j >= 0: j -= 1
        y.append(j)
    a.append(b)
for i in range(min(x),max(x)+1):
    for j in range(min(y),max(y)+1): print(a[i][j],end = "")
    print()


n, m = [int(x) for x in input().split()]
a = []
for i in range(n):
	a.append(input())
while '*' not in a[0]:
	a.pop(0)
while '*' not in a[-1]:
	a.pop(-1)
n = len(a)
while '*' not in (x[0] for x in a):
	for i in range(n):
		a[i] = a[i][1: ]
while '*' not in (x[-1] for x in a):
	for i in range(n):
		a[i] = a[i][: -1]
print('\n'.join(a))


n,m=[int(x) for x in input().split()]
leftopx=0
leftopy=0
rightbottomx=n-1
rightbottomy=m-1
rightopx=0
rightopy=m
leftbottomx=n
leftbottomy=0
g=[]
temp=0
for i in range(n):
    g.append(list(input()))
for i in range(n):
    for j in range(m):
        if(g[i][j]=='*'):
            leftopx=i
            leftopy=j
            temp=1
            break
    if(temp==1):
        break
temp=0
rightx=0
righty=0
for i in range(0,n):
    for j in range(m-1,-1,-1):
        if(g[i][j]=='*'):
            righty=max(righty,j)
            break
temp=0
for i in range(n-1,-1,-1):
    for j in range(m-1,-1,-1):
        if(g[i][j]=='*'):
            rightbottomx=i
            rightbottomy=j
            temp=1
            break
    if(temp==1):
        break
#print(leftopx,rightbottomx,righty,leftopy)
last=max(righty,rightbottomy)

for i in range(leftopx,rightbottomx+1):
    for j in range(leftopy,righty+1):
        print(g[i][j],end="")
    print()


n,m=[int(x) for x in input().split()]
leftopx=0
leftopy=0
rightbottomx=-1
rightbottomy=0
rightopx=-1
rightopy=-1
leftbottomx=0
leftbottomy=0
g=[]
temp=0
for i in range(n):
    g.append(list(input()))
for i in range(n):
    for j in range(m):
        if(g[i][j]=='*'):
            leftopx=i
            leftopy=j
            temp=1
            break
    if(temp==1):
        break
temp=0
lefty=m
righty=-1
for i in range(0,n):
    for j in range(0,m):
        if(g[i][j]=='*'):
            lefty=min(lefty,j)
            break
for i in range(0,n):
    for j in range(m-1,-1,-1):
        if(g[i][j]=='*'):
            righty=max(righty,j)
            break
temp=0
for i in range(n-1,-1,-1):
    for j in range(m-1,-1,-1):
        if(g[i][j]=='*'):
            rightbottomx=i
            rightbottomy=j
            temp=1
            break
    if(temp==1):
        break
#print(leftopx,rightbottomx,righty,leftopy)
last=max(righty,rightbottomy)

for i in range(leftopx,rightbottomx+1):
    for j in range(lefty,righty+1):
        print(g[i][j],end="")
    print()


n,m=[int(x) for x in input().split()]
leftopx=0
leftopy=0
rightbottomx=-1
rightbottomy=0
rightopx=-1
rightopy=-1
leftbottomx=0
leftbottomy=0
g=[]
temp=0
for i in range(n):
    g.append(list(input()))
for i in range(n):
    for j in range(m):
        if(g[i][j]=='*'):
            leftopx=i
            leftopy=j
            temp=1
            break
    if(temp==1):
        break
temp=0
rightx=0
righty=-1
for i in range(0,n):
    for j in range(m-1,-1,-1):
        if(g[i][j]=='*'):
            righty=max(righty,j)
            break
temp=0
for i in range(n-1,-1,-1):
    for j in range(m-1,-1,-1):
        if(g[i][j]=='*'):
            rightbottomx=i
            rightbottomy=j
            temp=1
            break
    if(temp==1):
        break
#print(leftopx,rightbottomx,righty,leftopy)
last=max(righty,rightbottomy)

for i in range(leftopx,rightbottomx+1):
    for j in range(leftopy,righty+1):
        print(g[i][j],end="")
    print()


a,b=map(int,input().split())
ar=[]
for i in range(a):
    x=input()
    ar.append(x)
x=[]
y=[]
for i in range(a):
    if '*' in ar[i]:
        y.append(i)
    for j in range(b):
        if ar[i][j]=='*':
            x.append(j)
# print(x,y)
x1=min(x)
x2=max(x)
y1=min(y)
y2=max(y)
for i in range(a):
    if i>=y1 and i<=y2:
        for j in range(x1,x2+1):
            print(ar[i][j],end="")
        print("")

# re
# a,b=map(int,input().split())
# ar=[]
# for i in range(a):
#     x=input()
#     ar.append(x)
# x=[]
# y=[]
# for i in range(a):
#     if '*' in ar[i]:
#         y.append(i)
#     for j in range(b):
#         if ar[i][j]=='*':
#             x.append(j)
# # print(x,y)
# x1=min(x)
# x2=max(x)
# y1=min(y)
# y2=max(y)
# for i in range(a):
#     if i>=y1 and i<=y2:
#         for j in range(x1,x2+1):
#             print(ar[i][j],end="")
#         print("")


a,b=map(int,input().split())
ar=[]
for i in range(a):
    x=input()
    ar.append(x)
x=[]
y=[]
for i in range(a):
    if '*' in ar[i]:
        y.append(i)
    for j in range(b):
        if ar[i][j]=='*':
            x.append(j)
# print(x,y)
x1=min(x)
x2=max(x)
y1=min(y)
y2=max(y)
for i in range(a):
    if i>=y1 and i<=y2:
        for j in range(x1,x2+1):
            print(ar[i][j],end="")
        print("")


n, m = map(int, input().split())
grid = [input() for i in range(n)]

minr, maxr, minc, maxc = n, -1, m, -1

for i in range(n):
    for j in range(m):
        if grid[i][j] == '*':
            minr = min(minr, i)
            maxr = max(maxr, i)
            minc = min(minc, j)
            maxc = max(maxc, j)

for i in range(minr, maxr+1):
    print(grid[i][minc:maxc+1])


x, y = map(int, input().split())
q = [input() for i in range(x)]
t = 0
while q[t] == '.' * y:
    t += 1
b = x
while q[b-1] == '.' * y:
    b -= 1
l = 0
while sum(i[l] == '*' for i in q) == 0:
    l += 1
r = y
while sum(i[r-1] == '*' for i in q) == 0:
    r -= 1
print('\n'.join(i[l:r] for i in q[t:b]))


n,m=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(input()))
x,y=[],[]
for i in range(n):
    for j in range(m):
        if(l[i][j]=='*'):
            x.append(i)
            y.append(j)
k=[]
for i in range(min(x),max(x)+1):
    d=[]
    for j in range(min(y),max(y)+1):
        d.append(l[i][j])
    k.append(d)
for i in k:
    print(''.join(i))


__author__ = 'Obriel Muga'

if __name__ == '__main__':
    lista = []
    filas,columnas = list(map(int,input().strip().split()))
    UL = False
    DU = False
    IZQ = 10000000000000
    DER = -1000000000000
    for i in range(filas):
        linea = input()
        if (UL):
            lista.append(linea)
        elif (not UL and '*' in linea):
            lista.append(linea)
            UL = True
    for i in range(len(lista) - 1, -1,-1):
        if ("*" not in lista[i]):
            del lista[i]
        else:
            break
    for valor in lista:
        a = valor.find('*')
        b = valor.rfind('*')
        if (a >= 0 and a <= IZQ):
            IZQ = a
        if (b >= 0 and b >= DER):
            DER = b
    for i in lista:
        print(i[IZQ:DER+1])


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int hl[N];
int out[N];
int ixd[N];

int main(){
	fastIO;
	int n,  m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0 ; i < n;i  ++ ){
		cin >> hl[i];
	}
	int p;
	int nx;
	int nxp;
	for(int i = n - 1; i >= 0 ; i -- ){
		p = i / bl;
		nx = i + hl[i];
		nxp = nx / bl;
		if(nxp > p){
			out[i] = 1;
			ixd[i] = nx;
		}
		else{
			out[i] = out[nx] + 1;
			ixd[i] = ixd[nx];
		}
	}
	int t;
	int pos;
	int pwr;
	int sx;
	int ret;
	int las;
	for(int i = 0 ; i < m ; i ++ ){
		cin >> t;
		if(t == 0){
			cin >> pos >> pwr;
			-- pos;
			hl[pos] = pwr;
			for(int j = pos ; j >= max(0, pos - (2 * bl)); j -- ){
				p = pos / bl;
				nx = pos + hl[pos];
				nxp = nx  / bl;
				if(nxp > p){
					out[pos] = 1;
					ixd[pos] = nx;
				}
				else{
					out[pos] = out[nx] + 1;
					ixd[i] = ixd[nx];
				}
			}
		}
		else{
			cin >> pos;
			-- pos;
			las = pos;
			ret = 0;
			while(pos < n){
				las = pos;
				ret += out[pos];
				pos = ixd[pos];
			}
			cout << las + 1 << " " << ret << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pw[N];
int nxt[N];
int jp[N];

int main(){
	fastIO;
	int n, m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0; i < n; i ++ ){
		cin >> pw[i];

	}

	int p;
	int nx;
	int nxp;

	for(int i = n-1; i >= 0 ; i -- ){
		nx = i + pw[i];
		p = i / bl;
		nxp = nx / bl;

		if(nxp > p || nx >= n){
			jp[i] = 1;
			nxt[i] = nx;
		}
		else{
			jp[i] = jp[nx] + 1;
			nxt[i] = nxt[nx];
		}

	}

	int ty;
	int a;
	int b;
	int tot, las;
	int il, ir;
	for(int i = 0 ; i < m; i ++ ){
		cin >> ty;
		if(ty == 0){
			cin >> a >> b;
			-- a;
			pw[a] = b;
			for(int j = a; j >= max(0, a - bl) ; j -- ){
				nx = j + pw[j];
				p = j / bl;
				nxp = nx / bl;
				if(nxp > p || nx >= n){
					jp[j] = 1;
					nxt[j] = nx;
				}
				else{
					jp[j] = jp[nx] + 1;
					nxt[j] = nxt[nx];
				}
			}
		}
		else{
			cin >> a;
			-- a;
			tot = 0;
			las = a;
			while(nxt[a] < n){
				las = a;
				tot += jp[a] ;
				a = nxt[a] ;
			}
			while(a < n){
				las = a;
				tot ++ ;
				a += pw[a];
			}
			cout << las + 1 << " " << tot << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pw[N];
int nxt[N];
int jp[N];

int main(){
	fastIO;
	int n, m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0; i < n; i ++ ){
		cin >> pw[i];

	}

	int p;
	int nx;
	int nxp;

	for(int i = n-1; i >= 0 ; i -- ){
		nx = i + pw[i];
		p = i / bl;
		nxp = nx / bl;

		if(nxp > p || nx >= n){
			jp[i] = 1;
			nxt[i] = nx;
		}
		else{
			jp[i] = jp[nx] + 1;
			nxt[i] = nxt[nx];
		}

	}

	int ty;
	int a;
	int b;
	int tot, las;
	int il, ir;
	for(int i = 0 ; i < m; i ++ ){
		cin >> ty;
		if(ty == 0){
			cin >> a >> b;
			-- a;
			pw[a] = b;
			for(int j = n - 1; j >= 0 ; j -- ){
				nx = j + pw[j];
				p = j / bl;
				nxp = nx / bl;
				if(nxp > p || nx >= n){
					jp[j] = 1;
					nxt[j] = nx;
				}
				else{
					jp[j] = jp[nx] + 1;
					nxt[j] = nxt[nx];
				}
			}
		}
		else{
			cin >> a;
			-- a;
			tot = 0;
			las = a;
			while(nxt[a] < n){
				las = a;
				tot += jp[a] ;
				a = nxt[a] ;
			}
			while(a < n){
				las = a;
				tot ++ ;
				a += pw[a];
			}
			cout << las + 1 << " " << tot << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int hl[N];
int out[N];
int ixd[N];

int main(){
	fastIO;
	int n,  m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0 ; i < n;i  ++ ){
		cin >> hl[i];
	}
	int p;
	int nx;
	int nxp;
	for(int i = n - 1; i >= 0 ; i -- ){
		p = i / bl;
		nx = i + hl[i];
		nxp = nx / bl;
		if(nxp > p){
			out[i] = 1;
			ixd[i] = nx;
		}
		else{
			out[i] = out[nx] + 1;
			ixd[i] = ixd[nx];
		}
	}
	int t;
	int pos;
	int pwr;
	int sx;
	int ret;
	int las;
	for(int i = 0 ; i < m ; i ++ ){
		cin >> t;
		if(t == 0){
			cin >> pos >> pwr;
			-- pos;
			hl[pos] = pwr;
			for(int j = pos ; j >= max(0, pos - bl); j -- ){
				p = j / bl;
				nx = j + hl[j];
				nxp = nx  / bl;
				if(nxp > p){
					out[j] = 1;
					ixd[j] = nx;
				}
				else{
					out[j] = out[nx] + 1;
					ixd[i] = ixd[nx];
				}
			}
		}
		else{
			cin >> pos;
			-- pos;
			las = pos;
			ret = 0;
			while(pos < n){
				las = pos;
				ret += out[pos];
				pos = ixd[pos];
			}
			cout << las + 1 << " " << ret << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pw[N];
int nxt[N];
int jp[N];

int main(){
	fastIO;
	int n, m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0; i < n; i ++ ){
		cin >> pw[i];

	}

	int p;
	int nx;
	int nxp;

	for(int i = n-1; i >= 0 ; i -- ){
		nx = i + pw[i];
		p = i / bl;
		nxp = nx / bl;

		if(nxp > p){
			jp[i] = 1;
			nxt[i] = nx;
		}
		else{
			jp[i] = jp[nx] + 1;
			nxt[i] = nxt[nx];
		}

	}

	int ty;
	int a;
	int b;
	int tot, las;
	for(int i = 0 ; i < m; i ++ ){
		cin >> ty;
		if(ty == 0){
			cin >> a >> b;
			-- a;
			pw[a] = b;
			for(int j = a; j >= max(0, a - bl); j -- ){
				nx = j + pw[j];
				p = j / bl;
				nxp = nx / bl;
				if(nxp > p){
					jp[j] = 1;
					nxt[j] = nx;
				}
				else{
					jp[j] = jp[nx] + 1;
					nxt[j] = nxt[nx];
				}
			}
		}
		else{
			cin >> a;
			-- a;
			tot = 0;
			las = a;
			while(a < n){
				las = a;
				tot += jp[a];
				a = nxt[a];
			}
			cout << las + 1 << " " << tot << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pw[N];
int nxt[N];
int jp[N];

int main(){
	fastIO;
	int n, m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0; i < n; i ++ ){
		cin >> pw[i];

	}

	int p;
	int nx;
	int nxp;

	for(int i = n-1; i >= 0 ; i -- ){
		nx = i + pw[i];
		p = i / bl;
		nxp = nx / bl;

		if(nxp > p){
			jp[i] = 1;
			nxt[i] = nx;
		}
		else{
			jp[i] = jp[nx] + 1;
			nxt[i] = nxt[nx];
		}

	}

	int ty;
	int a;
	int b;
	int tot, las;
	int il, ir;
	for(int i = 0 ; i < m; i ++ ){
		cin >> ty;
		if(ty == 0){
			cin >> a >> b;
			-- a;
			pw[a] = b;
			for(int j = n - 1; j >= 0 ; j -- ){
				nx = j + pw[j];
				p = j / bl;
				nxp = nx / bl;
				if(nxp > p){
					jp[j] = 1;
					nxt[j] = nx;
				}
				else{
					jp[j] = jp[nx] + 1;
					nxt[j] = nxt[nx];
				}
			}
		}
		else{
			cin >> a;
			-- a;
			tot = 0;
			las = a;
			while(a < n){
				las = a;
				tot += jp[a] ;
				a = nxt[a] ;
			}
			cout << las + 1 << " " << tot << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pw[N];
int nxt[N];
int jp[N];

int main(){
	fastIO;
	int n, m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0; i < n; i ++ ){
		cin >> pw[i];

	}

	int p;
	int nx;
	int nxp;

	for(int i = n-1; i >= 0 ; i -- ){
		nx = i + pw[i];
		p = i / bl;
		nxp = nx / bl;

		if(nxp > p || nx >= n){
			jp[i] = 1;
			nxt[i] = nx;
		}
		else{
			jp[i] = jp[nx] + 1;
			nxt[i] = nxt[nx];
		}

	}

	int ty;
	int a;
	int b;
	int tot, las;
	int il, ir;
	for(int i = 0 ; i < m; i ++ ){
		cin >> ty;
		if(ty == 0){
			cin >> a >> b;
			-- a;
			pw[a] = b;
			for(int j = n - 1; j >= 0 ; j -- ){
				nx = j + pw[j];
				p = j / bl;
				nxp = nx / bl;
				if(nxp > p || nx >= n){
					jp[j] = 1;
					nxt[j] = nx;
				}
				else{
					jp[j] = jp[nx] + 1;
					nxt[j] = nxt[nx];
				}
			}
		}
		else{
			cin >> a;
			-- a;
			tot = 0;
			las = a;
			while(a < n){
				las = a;
				tot += jp[a] ;
				a = nxt[a] ;
			}
			while(a < n){
				las = a;
				a += pw[a];
			}
			cout << las + 1 << " " << tot << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int hl[N];
int out[N];
int ixd[N];

int main(){
	fastIO;
	int n,  m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0 ; i < n;i  ++ ){
		cin >> hl[i];
	}
	int p;
	int nx;
	int nxp;
	for(int i = n - 1; i >= 0 ; i -- ){
		p = i / bl;
		nx = i + hl[i];
		nxp = nx / bl;
		if(nxp > p){
			out[i] = 1;
			ixd[i] = nx;
		}
		else{
			out[i] = out[nx] + 1;
			ixd[i] = ixd[nx];
		}
	}
	int t;
	int pos;
	int pwr;
	int sx;
	int ret;
	int las;
	for(int i = 0 ; i < m ; i ++ ){
		cin >> t;
		if(t == 0){
			cin >> pos >> pwr;
			-- pos;
			hl[pos] = pwr;
			sx = p * bl;
			for(int j = pos ; j >= sx; j -- ){
				p = pos / bl;
				nx = pos + hl[pos];
				nxp = nx  / bl;
				if(nxp > p){
					out[pos] = 1;
					ixd[pos] = nx;
				}
				else{
					out[pos] = out[nx] + 1;
					ixd[i] = ixd[nx];
				}
			}
		}
		else{
			cin >> pos;
			-- pos;
			ret = 0;
			while(pos < n){
				las = pos;
				ret += out[pos];
				pos = ixd[pos];
			}
			cout << las + 1 << " " << ret << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pw[N];
int nxt[N];
int jp[N];

int main(){
	fastIO;
	int n, m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0; i < n; i ++ ){
		cin >> pw[i];

	}

	int p;
	int nx;
	int nxp;

	for(int i = n-1; i >= 0 ; i -- ){
		nx = i + pw[i];
		p = i / bl;
		nxp = nx / bl;

		if(nxp > p){
			jp[i] = 1;
			nxt[i] = nx;
		}
		else{
			jp[i] = jp[nx] + 1;
			nxt[i] = nxt[nx];
		}

	}

	int ty;
	int a;
	int b;
	int tot, las;
	for(int i = 0 ; i < m; i ++ ){
		cin >> ty;
		if(ty == 0){
			cin >> a >> b;
			-- a;
			pw[a] = b;
			for(int j = a; j >= max(0, a - bl); j -- ){
				nx = j + pw[j];
				p = j / bl;
				nxp = nx / bl;
				if(nxp > p){
					jp[j] = 1;
					nxt[j] = nx;
				}
				else{
					jp[j] = jp[nx] + 1;
					nxt[j] = nxt[nx];
				}
			}
		}
		else{
			cin >> a;
			-- a;
			tot = 0;
			las = a;
			while(a < n){
				las = a;
				tot ++ ;
				a += pw[a];
			}
			cout << las + 1 << " " << tot << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pw[N];
int nxt[N];
int jp[N];

int main(){
	fastIO;
	int n, m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0; i < n; i ++ ){
		cin >> pw[i];

	}

	int p;
	int nx;
	int nxp;

	for(int i = n-1; i >= 0 ; i -- ){
		nx = i + pw[i];
		p = i / bl;
		nxp = nx / bl;

		if(nxp > p){
			jp[i] = 1;
			nxt[i] = nx;
		}
		else{
			jp[i] = jp[nx] + 1;
			nxt[i] = nxt[nx];
		}

	}

	int ty;
	int a;
	int b;
	int tot, las;
	int il, ir;
	for(int i = 0 ; i < m; i ++ ){
		cin >> ty;
		if(ty == 0){
			cin >> a >> b;
			-- a;
			pw[a] = b;
			for(int j = n - 1; j >= 0 ; j -- ){
				nx = j + pw[j];
				p = j / bl;
				nxp = nx / bl;
				if(nxp > p){
					jp[j] = 1;
					nxt[j] = nx;
				}
				else{
					jp[j] = jp[nx] + 1;
					nxt[j] = nxt[nx];
				}
			}
		}
		else{
			cin >> a;
			-- a;
			tot = 0;
			las = a;
			while(a < n){
				las = a;
				tot += jp[a] ;
				a = nxt[a] ;
			}
			while(a < n){
				las = a;
				a += pw[a];
			}
			cout << las + 1 << " " << tot << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef double db;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int hl[N];
int out[N];
int ixd[N];

int main(){
	fastIO;
	int n,  m;
	cin >> n >> m;
	int bl = int(sqrt(n));
	for(int i = 0 ; i < n;i  ++ ){
		cin >> hl[i];
	}
	int p;
	int nx;
	int nxp;
	for(int i = n - 1; i >= 0 ; i -- ){
		p = i / bl;
		nx = i + hl[i];
		nxp = nx / bl;
		if(nxp > p){
			out[i] = 1;
			ixd[i] = nx;
		}
		else{
			out[i] = out[nx] + 1;
			ixd[i] = ixd[nx];
		}
	}
	int t;
	int pos;
	int pwr;
	int sx;
	int ret;
	int las;
	for(int i = 0 ; i < m ; i ++ ){
		cin >> t;
		if(t == 0){
			cin >> pos >> pwr;
			-- pos;
			hl[pos] = pwr;
			for(int j = pos ; j >= max(0, pos - bl); j -- ){
				p = j / bl;
				nx = j + hl[j];
				nxp = nx  / bl;
				if(nxp > p){
					out[j] = 1;
					ixd[j] = nx;
				}
				else{
					out[j] = out[nx] + 1;
					ixd[j] = ixd[nx];
				}
			}
		}
		else{
			cin >> pos;
			-- pos;
			las = pos;
			ret = 0;
			while(pos < n){
				las = pos;
				ret += out[pos];
				pos = ixd[pos];
			}
			cout << las + 1 << " " << ret << "\n";
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 300;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];
int n;

inline void modify(int L,int R)
{
	for(int i = R; i >= L; i --)
	{
		int j = i+p[i];
		if( j >= n )
		{
			next[i] = -1;
			c[i] = 1;
		}
		else if( j/sqrt == i/sqrt)
		{
			next[i] = next[j];
			c[i] = c[j]+1;
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}
	}
}

int32_t main()
{
//	IOS;
	int m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];
	modify(0,n-1);
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0;
		 	while(next[x] != -1)
			{
				sum += c[x];
				x = next[x];
			}
			while(x + p[x] < n)
			{
				sum++;
				x += p[x];
			}
			cout << x+1 <<  ' ' << sum+1 << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			modify((x/sqrt)*sqrt,(x/sqrt)*sqrt + sqrt-1);
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 333;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];
int n;

inline void modify(int L,int R)
{
	for(int i = R; i >= L; i --)
	{
		int j = i+p[i];
		if( j >= n )
		{
			next[i] = -1;
			c[i] = 1;
		}
		else if( j/sqrt == i/sqrt)
		{
			next[i] = next[j];
			c[i] = c[j]+1;
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}
	}
}

int32_t main()
{
//	IOS;
	int m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];
	modify(0,n-1);
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0;
		 	while(next[x] != -1)
			{
				sum += c[x];
				x = next[x];
			}
			while(x + p[x] < n)
			{
				sum++;
				x += p[x];
			}
			cout << x+1 <<  ' ' << sum+1 << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			modify((x/sqrt)*sqrt,x);
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 300;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];
int n;

inline void modify(int L,int R)
{
	for(int i = R; i >= L; i --)
	{
		int j = i+p[i];
		if( j >= n )
		{
			next[i] = -1;
			c[i] = 1;
		}
		else if( j/sqrt == i/sqrt)
		{
			next[i] = next[j];
			c[i] = c[j]+1;
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}
	}
}

int32_t main()
{
//	IOS;
	int m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];i
	modify(0,n-1);
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0;
		 	while(next[x] != -1)
			{
				sum += c[x];
				x = next[x];
			}
			while(x + p[x] < n)
			{
				sum++;
				x += p[x];
			}
			cout << x+1 <<  ' ' << sum+1 << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			modify(x/sqrt,x/sqrt + sqrt-1);
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 330;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];

int32_t main()
{
	IOS;
	int n,m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];
	for(int i = n-1; i >= 0; i--)
	{
		int j = i+p[i];
		if( j >= n ) { next[i] = -1; c[i] = 1; }
		else
		if( j/sqrt == i/sqrt )
		{
			c[i] = c[j]+1;
			next[i] = next[j];
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}

	}
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0 ;
			int last = x;
			while(x != -1)
			{
				sum += c[x];
				last = x;
				x = next[x];
			}
			x = last;
			while( x < n){
				last = x;
				x += p[x];
			}
		 	cout << last+1 <<  ' ' << sum << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			for(int j = x/sqrt + sqrt - 1; j >= x/sqrt; j --)
			{
				int k = j+p[j];
				if( k >= n)
				{
					next[j] = -1;
					c[j] = 1;
				}
				else if( j/sqrt == k/sqrt)
				{
					c[j] = c[k]+1;
					next[j] = next[k];
				}
				else
				{
					next[j] = k;
					c[j] = 1;
				}
			}
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 530;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];
int n;

inline void modify(int L,int R)
{
	for(int i = R; i >= L; i --)
	{
		int j = i+p[i];
		if( j >= n )
		{
			next[i] = -1;
			c[i] = 1;
		}
		else if( j/sqrt == i/sqrt)
		{
			next[i] = next[j];
			c[i] = c[j]+1;
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}
	}
}

int32_t main()
{
	IOS;
	int m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];
	modify(0,n-1);
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0 ;
			int last = x;
			while(x != -1)
			{
				sum += c[x];
				last = x;
				x = next[x];
			}
			x = last;
			while( x < n){
				last = x;
				x += p[x];
			}
		 	cout << last+1 <<  ' ' << sum << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			modify(x/sqrt,x/sqrt + sqrt-1);
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 333;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];
int n;

inline void modify(int L,int R)
{
	for(int i = R; i >= L; i --)
	{
		int j = i+p[i];
		if( j >= n )
		{
			next[i] = -1;
			c[i] = 1;
		}
		else if( j/sqrt == i/sqrt)
		{
			next[i] = next[j];
			c[i] = c[j]+1;
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}
	}
}

int32_t main()
{
	IOS;
	int m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];
	modify(0,n-1);
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0;
		 	while(next[x] != -1)
			{
				sum += c[x];
				x = next[x];
			}
			while(x + p[x] < n)
			{
				sum++;
				x += p[x];
			}
			cout << x+1 <<  ' ' << sum+1 << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			modify((x/sqrt)*sqrt,x);
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 250;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];
int n;

inline void modify(int L,int R)
{
	for(int i = R; i >= L; i --)
	{
		int j = i+p[i];
		if( j >= n )
		{
			next[i] = -1;
			c[i] = 1;
		}
		else if( j/sqrt == i/sqrt)
		{
			next[i] = next[j];
			c[i] = c[j]+1;
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}
	}
}

int32_t main()
{
//	IOS;
	int m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];
	modify(0,n-1);
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0;
		 	while(next[x] != -1)
			{
				sum += c[x];
				x = next[x];
			}
			while(x + p[x] < n)
			{
				sum++;
				x += p[x];
			}
			cout << x+1 <<  ' ' << sum+1 << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			modify(x/sqrt,x/sqrt + sqrt-1);
		}
	}
	return 0;
}


// In The Name Of God

// I don't believe in CHANCE
// I believe in RAGE
// I believe in PAIN
// I believe in FEAR

// Lately I’ve been hard to reach
// I’ve been too long on my own
// Everybody has a private world
// Where they can be alone
// Are you calling me?
// Are you trying to get through?

#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define sqrt HIBI
#define next GOODBYE
const ll inf = ~0ull/4;
const ll maxn = 110000;
const int sqrt = 330;

/////////////////////////////////////////////////////////////////////

int p[maxn];
int c[maxn];
int next[maxn];
int n;

inline void modify(int L,int R)
{
	for(int i = R; i >= L; i --)
	{
		int j = i+p[i];
		if( j >= n )
		{
			next[i] = -1;
			c[i] = 1;
		}
		else if( j/sqrt == i/sqrt)
		{
			next[i] = next[j];
			c[i] = c[j]+1;
		}
		else
		{
			next[i] = j;
			c[i] = 1;
		}
	}
}

int32_t main()
{
	IOS;
	int m;
	cin >> n >> m;
	for2(i,0,n) cin >> p[i];
	modify(0,n-1);
	for2(i,0,m)
	{
		int t;
		cin >> t;
		if(t)
		{
			int x;
			cin >> x;
			x--;
			int sum = 0;
		 	while(next[x] != -1)
			{
				sum += c[x];
				x = next[x];
			}
			while(x + p[x] < n)
			{
				sum++;
				x += p[x];
			}
			cout << x+1 <<  ' ' << sum+1 << endl;
		}
		else
		{
			int x,y;
			cin >> x >> y;
			x--;
			p[x] = y;
			modify(x/sqrt,x/sqrt + sqrt-1);
		}
	}
	return 0;
}