import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main{

    static class InputReader {

        final private int BUFFER_SIZE = 1 << 17;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public InputReader(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public byte next() {
            try {
                return read();
            } catch (Exception e) {
                throw new InputMismatchException();
            }
        }

        public String nextString() {
            StringBuilder sb = new StringBuilder("");
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            do {
                sb.append((char) c);
                c = next();
            } while (c > ' ');
            return sb.toString();
        }

        public int nextInt() {
            int ret = 0;
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            boolean neg = c == '-';
            if (neg) {
                c = next();
            }
            do {
                ret = (ret << 3) + (ret << 1) + c - '0';
                c = next();
            } while (c > ' ');
            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }
    }

    public static void main(String arg[]) throws IOException {

     InputReader r=new InputReader(System.in);
       // BufferedReader r=new BufferedReader(new FileReader("input.txt"));
    //   BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
   //     BufferedWriter wr=new BufferedWriter(new PrintWriter("output.txt"));
        PrintWriter p=new PrintWriter(System.out,false);
  int n=r.nextInt();
int c=-1;
int a[]=new int[n];
for(int i=0;i<n;i++)
  {
     a[i]=r.nextInt();
  }
for(int i=0;i<n-1;i++)
{
    if(a[i]>a[i+1])
        c=i;
}
p.println(c+1);
 p.flush();

}}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main{

    static class InputReader {

        final private int BUFFER_SIZE = 1 << 17;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public InputReader(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public byte next() {
            try {
                return read();
            } catch (Exception e) {
                throw new InputMismatchException();
            }
        }

        public String nextString() {
            StringBuilder sb = new StringBuilder("");
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            do {
                sb.append((char) c);
                c = next();
            } while (c > ' ');
            return sb.toString();
        }

        public int nextInt() {
            int ret = 0;
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            boolean neg = c == '-';
            if (neg) {
                c = next();
            }
            do {
                ret = (ret << 3) + (ret << 1) + c - '0';
                c = next();
            } while (c > ' ');
            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }
    }

    public static void main(String arg[]) throws IOException {

     InputReader r=new InputReader(System.in);
       // BufferedReader r=new BufferedReader(new FileReader("input.txt"));
    //   BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
   //     BufferedWriter wr=new BufferedWriter(new PrintWriter("output.txt"));
        PrintWriter p=new PrintWriter(System.out,false);
  int n=r.nextInt();
int c=0;
for(int i=0;i<n;i++)
  {
     if(r.nextInt()==1)
         break;
     c++;
  }p.println(c);
 p.flush();

}}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main{

    static class InputReader {

        final private int BUFFER_SIZE = 1 << 17;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public InputReader(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public byte next() {
            try {
                return read();
            } catch (Exception e) {
                throw new InputMismatchException();
            }
        }

        public String nextString() {
            StringBuilder sb = new StringBuilder("");
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            do {
                sb.append((char) c);
                c = next();
            } while (c > ' ');
            return sb.toString();
        }

        public int nextInt() {
            int ret = 0;
            byte c = next();
            while (c <= ' ') {
                c = next();
            }
            boolean neg = c == '-';
            if (neg) {
                c = next();
            }
            do {
                ret = (ret << 3) + (ret << 1) + c - '0';
                c = next();
            } while (c > ' ');
            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }
    }

    public static void main(String arg[]) throws IOException {

     InputReader r=new InputReader(System.in);
       // BufferedReader r=new BufferedReader(new FileReader("input.txt"));
    //   BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
   //     BufferedWriter wr=new BufferedWriter(new PrintWriter("output.txt"));
        PrintWriter p=new PrintWriter(System.out,false);
  int n=r.nextInt();
int c=0;
int a[]=new int[n];
for(int i=0;i<n;i++)
  {
     a[i]=r.nextInt();
  }
for(int i=0;i<n-1;i++)
{
    if(a[i]>a[i+1])
        c=i;
}
p.println(c+1);
 p.flush();

}}


/*
<title> IN THE NAME OF GOD </title>
<p1> I'm faraz azadi ;) <p1>
<account's in algorithm's contest site> frez & frez_95 </account's>
<Github> frez-95 </Github>
*/
// code compile and test in g++(5.2.1) in Ubuntu
#define EPS 1e-7
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<math.h>
#include<queue>
#include<cmath>
#include<stack>
#include<cstdio>
#include<string.h>
#define ll long long
#define ld long long double
#define LSone(n) ((n)&(-n))
using namespace std;
int dp[10000];
int main()
{
	int n;cin>>n;
	vector<int> V;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		V.push_back(x);
	}
	int minn=V[0];
	int index=0;
	for(int i=0;i<n;i++)
	{
		if(minn>V[i])
		{
			minn=V[i];
			index=i;
		}
	}
	cout<<index;
    return 0;
}


/*
<title> IN THE NAME OF GOD </title>
<p1> I'm faraz azadi ;) <p1>
<account's in algorithm's contest site> frez & frez_95 </account's>
<Github> frez-95 </Github>
*/
// code compile and test in g++(5.2.1) in Ubuntu
#define EPS 1e-7
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<math.h>
#include<queue>
#include<cmath>
#include<stack>
#include<cstdio>
#include<string.h>
#define ll long long
#define ld long long double
#define LSone(n) ((n)&(-n))
using namespace std;
int dp[10000];
int main()
{
	int n;cin>>n;
	int x;cin>>x;
	n--;
	int minn=x;
	int javab=0;
	while(n--)
	{
		cin>>x;
		if(minn>x)javab++;
		minn=min(minn,x);
	}
	cout<<javab;
    return 0;
}


#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
//dar hale hazer daram ba donafar mosabege midam yeki yashare yeki RM e ;))
int arr[1000005];
int main()
{
	int f=1;
	int javab=0;
	int n;cin>>n;
	while(n--)
	{
		int g;cin>>g;
		if(g==f){
			f++;
			while(arr[f])f++;
		}
		else
		{
			javab++;
			arr[g]=1;
		}
	}
	cout<<javab;
	return 0;
}


#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
//dar hale hazer daram ba donafar mosabege midam yeki yashare yeki RM e ;))
int arr[1000005];
int main()
{
	int f=1;
	int javab=0;
	int n;cin>>n;
	int d=0;
	while(n--)
	{
		d++;
		int g;cin>>g;
		if(g==f){
			f++;
			while(arr[f])f++;
		}
		else
		{
			javab=d;
			arr[g]=1;
		}
	}
	cout<<javab;
	return 0;
}


/*وَقُلِ اعْمَلُوا فَسَيَرَى اللَّهُ عَمَلَكُمْ وَرَسُولُهُ وَالْمُؤْمِنُونَ ۖ وَسَتُرَدُّونَ إِلَىٰ عَالِمِ الْغَيْبِ وَالشَّهَادَةِ فَيُنَبِّئُكُم بِمَا كُنتُمْ تَعْمَلُونَ */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define MOAE                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

/*yarb<3*/
int main()
{
	/*بسم الله الرحمن الرحيم*/
	MOAE;
	//freopen("tabs.in", "r", stdin);
	ll n;
	cin >> n;
	ll a[n], cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = n - 1; i > 0; i--)
	{
		if (a[i] <= a[i - 1])
			cnt++;
	}
	cout << cnt << endl;
	//خزان أحزان XD )<:
}


/*وَقُلِ اعْمَلُوا فَسَيَرَى اللَّهُ عَمَلَكُمْ وَرَسُولُهُ وَالْمُؤْمِنُونَ ۖ وَسَتُرَدُّونَ إِلَىٰ عَالِمِ الْغَيْبِ وَالشَّهَادَةِ فَيُنَبِّئُكُم بِمَا كُنتُمْ تَعْمَلُونَ */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define MOAE                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

/*yarb<3*/
int main()
{
	/*بسم الله الرحمن الرحيم*/
	MOAE;
	//freopen("tabs.in", "r", stdin);
	ll n;
	cin >> n;
	ll a[n], cnt = 1;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = n - 1; i > 0; i--)
	{
		if (a[i] > a[i - 1])
			cnt++;
		else
		{
			break;
		}
	}
	cout << n - cnt << endl;
	//خزان أحزان XD )<:
}


/*وَقُلِ اعْمَلُوا فَسَيَرَى اللَّهُ عَمَلَكُمْ وَرَسُولُهُ وَالْمُؤْمِنُونَ ۖ وَسَتُرَدُّونَ إِلَىٰ عَالِمِ الْغَيْبِ وَالشَّهَادَةِ فَيُنَبِّئُكُم بِمَا كُنتُمْ تَعْمَلُونَ */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define MOAE                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

/*yarb<3*/
int main()
{
	/*بسم الله الرحمن الرحيم*/
	MOAE;
	//freopen("tabs.in", "r", stdin);
	ll n;
	cin >> n;
	ll a[n], cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = n - 1; i > 0; i--)
	{
		if (a[i] < a[i - 1])
			cnt++;
	}
	cout << cnt << endl;
	//خزان أحزان XD )<:
}


#include<bits/stdc++.h>
#define ll long long
#define loop(w,e) for(ll w=1;w<=e;w++)
#define lop(w,e) for(ll w=0;w<e;w++)
#define mem(x,y) memset(x,y,sizeof(x))

using namespace std;

ll ar[100007];

int main()
{
    ll n;

    while(cin>>n){
        ll cnt=0;
        for(ll i=1; i<=n; i++){
            cin>>ar[i];
            if(ar[i]==1)
                cnt=i;
        }
        cout<<(cnt-1)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define loop(w,e) for(ll w=1;w<=e;w++)
#define lop(w,e) for(ll w=0;w<e;w++)
#define mem(x,y) memset(x,y,sizeof(x))

using namespace std;

ll ar[100007];

int main()
{
    ll n;

    while(cin>>n){
    ll cnt=0;
    if(n!=1)
    {
        cin>>ar[1];
        for(ll i=2; i<=n; i++)
        {
            cin>>ar[i];

            if(ar[i]<ar[i-1])
                cnt++;
        }
        cout<<cnt<<endl;

    }
    else
    {
        cin>>ar[0];
        if(ar[0]!=1)
            cout<<"1"<<endl;
        else
            cout<<"0"<<endl;
    }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define loop(w,e) for(ll w=1;w<=e;w++)
#define lop(w,e) for(ll w=0;w<e;w++)
#define mem(x,y) memset(x,y,sizeof(x))

using namespace std;

ll ar[100007];

int main()
{
    ll n;

    while(cin>>n)
    {
        ll cnt=0;
        cin>>ar[1];
        for(ll i=2; i<=n; i++)
        {
            cin>>ar[i];
            if(ar[i]<ar[i-1])
            cnt=i;
        }
        if(cnt!=0)
        cout<<(cnt-1)<<endl;
        else
            cout<<cnt<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char** argv) {
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>t;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		t.insert(t.begin(),x);
	}
	int m=n;
	for(int i=0;i<n;i++)
	{
		if(t[i]>t[i+1])
			m--;
		else
		{
			m--;
			break;
		}
	}
	cout<<m;

	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char** argv) {
	std::ios::sync_with_stdio(false);
	long n;
	cin>>n;
	int t[n];
	for(long i=n-1;i>=0;i--)
	{
		cin>>t[i];
	}
	long m=n;
	for(long i=0;i<n;i++)
	{
		if(t[i]>t[i+1])
			m--;
		else
		{
			m--;
			break;
		}
	}
	cout<<m;

	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char** argv) {

	int n;
	cin>>n;
	vector<int>t;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		t.insert(t.begin(),x);
	}
	int m=n;
	for(int i=0;i<n;i++)
	{
		if(t[i]>t[i+1])
			m--;
		else
		{
			m--;
			break;
		}
	}
	cout<<m;

	return 0;
}


#include <iostream>

using namespace std;

int main(int argc, char** argv) {

	int n;
	cin>>n;
	int t[n];
	for(int i=0;i<n;i++)
	{
		cin>>t[i];
	}
	int k=0;
	for(int i=1;i<n;i++)
	{
		if(t[i]<t[i-1])
		k++;
	}
	cout<<k;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int A[100010];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>A[i];
        }
        int cnt=1;
        int flag=0;
        for(int j=1;j<n;j++)
        {
            if(A[j]<A[j-1])
            {
                cnt=1;
            }
            if(A[j]>A[j-1])
            {
                cnt++;
            }
        }
        printf("%d\n",n-cnt);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int A[100010];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>A[i];
        }
        int cnt=0;
        if(n==1)
        {
            cnt=1;
        }
        else
        {
            for(int j=0;j<n-1;j++)
            {
                if(A[j]>A[j+1])
                {
                    cnt++;
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int A[100010];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>A[i];
        }
        int cnt=1;
        int flag=0;
        int z=0;
        for(int j=1;j<n;j++)
        {
            if(flag==1&&A[j]<A[j-1])
            {
                cnt--;
                break;
            }
            if(A[j]>A[j-1])
            {
                cnt++;
                flag=1;
            }
        }
        printf("%d\n",n-cnt);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n;
    vector<int> v = {0};
    fr(n) {
        cin >> a;
        if (a > v.back()) v.push_back(a);
        else *lower_bound(v.begin(), v.end(), a) = a;
    }
    cout << n - v.size() + 1;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, z = 0;
    cin >> n;
    fr(n) cin >> a[i];
    reverse(a, a + n);
    while (a[z] > a[z + 1] && z < n - 1) z++;
    cout << n - z - 1;
}


#include <stdio.h>
const int N=100050;
int sol,a[N],x[N];
int main()
{
	int n,i;
	scanf("%i",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%i",&x[i]);
		a[x[i]]=i;
	}
	for(i=1;i<=n;i++)
	{
		if(a[x[i]]<a[x[i]-1]) sol++;
	}
	printf("%i\n",sol);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,idx,cnt=0;
int a[N];

int main()
{
    cin>>n;
    for(int i=0;i<n;i++){cin>>a[i]; if(a[i]==1) idx=i;}
    for(int i=0;i<n;i++){
        if(i<idx) cnt++;
        else if(i==idx) continue;
        else{
            if(a[i]<a[i-1]) cnt+=i;
        }
    }
    cout<<cnt;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,idx,cnt=0;
int a[N];

int main()
{
    cin>>n;
    for(int i=0;i<n;i++){cin>>a[i]; if(a[i]==1) idx=i;}
    for(int i=0;i<n;i++){
        if(i<idx) cnt++;
        else if(i==idx) continue;
        else{
            if(a[i]<a[i-1]) cnt=i;
        }
    }
    cout<<cnt;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,idx,cnt=0;
int a[N];

int main()
{
    cin>>n;
    for(int i=0;i<n;i++){cin>>a[i]; if(a[i]==1) idx=i;}
    for(int i=0;i<n;i++){
        if(i<idx) cnt++;
        else if(i==idx) continue;
        else{
            if(a[i]<a[i-1]) cnt++;
        }
    }
    cout<<cnt;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> inline T sqr(T t) {return t*t;}
#define pb push_back
#define mp make_pair
#define endl "\n"

inline void files(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef _WIN32
        return;
    #endif // _WIN32
    //freopen("lca.in", "r", stdin);//freopen("output.out", "w", stdout);
}

int n, k, a[200100], ans;

int main(){
    //files();
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n-1; i >= 1; i--){
        if (a[i] > a[i+1])
            return cout << (i), 0;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> inline T sqr(T t) {return t*t;}
#define pb push_back
#define mp make_pair
#define endl "\n"

inline void files(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef _WIN32
        return;
    #endif // _WIN32
    //freopen("lca.in", "r", stdin);//freopen("output.out", "w", stdout);
}

int n, k, a[200100], ans;

int main(){
    //files();
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n-1; i >= 1; i--){
        if (a[i] > a[i+1])
            return cout << (i), 0;
    }
    cout << 0;
}


#include <stdio.h>

int main(){
	int n;
	int a;
	int last;
	int res = 0;
	int cnt = 0;
	scanf("%d%d", &n, &last);
	while (--n){
		scanf("%d", &a);
		cnt++;
		if (last > a) res=cnt;
		last = a;
	}

	printf("%d", res);
}


#include <stdio.h>

int main(){
	int n;
	int a;
	int last;
	int res = 0;
	int cnt = 0;
	scanf("%d%d",&n,&last);
	while (--n){
		scanf("%d",&a);
		if (last > a) cnt++;
		else{
			res += cnt;
			cnt = 0;
		}
		last = a;
	}
	res += cnt;
	printf("%d",res);
}


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

int main() {
	int n;
	cin>>n;
	int k, c=0, s=1;
	for(int i=1; i<=n; i++) {
		int a;
		cin>>a;
		if(i==1) k=a;
		if(a<k) {
			c+=s;
			s=1;
		}
		else if(a>k) s++;
		k=a;
	}
	cout<<c<<endl;
}


from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    n=int(stdin.readline())
    a=list(map(int,stdin.readline().split()))
    if len(set(a))==1:
        print(-1)
    else:print(*(sorted(a)))


a=int(input())
b=list(map(int,input().split()))
b.sort()
if sum(b[:a])!=sum(b[a:]):
    print(*b)
else:
    print("-1")


a=int(input())
b=list(map(int,input()))
b.sort()
if sum(b[:a])!=sum(b[a:]):
    print(b)
else:
    print("-1")


a=int(input())
b=list(map(int,input()))
b.sort()
if sum(b[:a])!=sum(b[a:])
    print(b)
else:
    print("-1")


# You'll never get ahead of anyone as long as you try to get even with him. Lou Holtz
# by : Blue Edge - Create some chaos

n=int(input())
a=list(map(int,input().split()))
a.sort()
if sum(a[:n])==sum(a[n:]):
    print(-1)
else:
    print(*a)


n = int(input())
arr = sorted([int(p) for p in input().split()])
if sum(arr[:n]) != sum(arr[n:]):
	print(*arr)
else:
	print(-1)


import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
if len(set(l)) == 1:
	print("NO")
else:
	print("YES")


import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
if len(set(l)) == 1:
	print(-1)
else:
	l = sorted(l)
	print(*l)


import sys
input = sys.stdin.readline

n = int(input())
l = list(map(input().split()))
if len(set(l)) == 1:
	print("NO")
else:
	print("YES")


## necessary imports
import sys
input = sys.stdin.readline
# from math import ceil, floor, factorial;

def ceil(x, y):
    return (x + y - 1)//y;

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

## gcd function
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
    if(k > n - k):
        k = n - k
    res = 1
    for i in range(k):
        res = res * (n - i)
        res = res / (i + 1)
    return int(res)

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
    if hi == None:
        hi = len(a);
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e7 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve()
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

n = int(input()); a = sorted(int_array());
if sum(a[:n]) != sum(a[n:]):
    print(*a);
else:
    print(-1);


n = int(input());
array = list(map(int, input().split()))

array.sort()
max1 = max(array)
max2 = array[0]
if max1 == max2:
  print(-1)
  exit
else:
  for i in range(2*n):
   print(array[i], end = ' ')


n = int(input());
array = list(map(int, input().split()))
b=0
'''
for i in range(1,(2*n)-1):
  for j in range(1,2*n):
    if array[i] > array[j] :
      b = array[i]
      array[i] = array[j]
      array[j] = b
'''
array.sort()
max1 = max(array)
if max1 == array[1]:
  print(-1)
  exit()

for i in range(2*n):
   print(array[i], end = ' ')


n = int(input())
a = [int(i) for i in input().split()]
first = sum(a[:n])
second = sum(a[n:])
f = False
for i in range(n):
    if f:
        break
    for j in range(n, 2*n):
        if first - a[i] + a[j] != second + a[i] - a[j]:
            f = True
            a[i], a[j] = a[j], a[i]
            break
if not f:
    print(-1)
else:
    print(*a)


n = int(input())
a = [int(i) for i in input().split()]
first = sum(a[:n])
second = sum(a[n:])
if first == second:
    f = False
    for i in range(n):
        if f:
            break
        for j in range(n, 2*n):
            if first - a[i] + a[j] != second + a[i] - a[j]:
                f = True
                a[i], a[j] = a[j], a[i]
                break
    if not f:
        print(-1)
    else:
        print(*a)
else:
    print(*a)


n= int(input())

l = list(map(int,input().split()))

sum1= sum(l[:n])
sum2 = sum(l[n:])
if sum1!=sum2:
    print(*l)
else:
    a = l[:n]
    b = l[n:]
    flag = 0
    for i in range(n):
        z = a[i]
        for j in range(n):
            if z!=b[j]:
                flag = 1
                a[i],b[j] = b[j],a[i]
                break
        if flag == 1:
            break
    if flag == 1:
        print(*(a+b))
    else:
        print(-1)


n= int(input())

l = list(map(int,input().split()))

sum1= sum(l[:n])
sum2 = sum(l[n:])
if sum1!=sum2:
    print(*l)
else:
    a = l[:n]
    b = l[n:]
    flag = 0
    for i in range(n):
        if l[i]!=l[n+i]:
            flag = 1
            l[i],l[n+i] = l[n+i],l[i]
            break
    if flag == 1:
        print(*l)
    else:
        print(-1)


n=int(input())

l=list(map(int,input().split()))
l.sort()
sum1=0
sum2=0

for i in range(n):
	sum1=sum1+l[i]
	sum2=sum2+l[2*n-1-i]

if (sum1==sum2):
	print("-1")
else:
	for i in range(2*n):
		print(l[i],end=" ")


n,x,a,y,b=input().split()
n=int(n)
a=int(a)
b=int(b)
x=int(x)
y=int(y)
flag=0
if ((x-a)%n)<=((y-b)%n):

	if (x<a):

		for i in range(x,a+1):
			x=(x+1)%n
			y=(y-1)%n
			print(x,y)
			if (x==y):
				print("YES")
				flag=1
				break
		if flag==0:
			print("NO")

	elif (x>a):

		for i in range(x,n+a):
			x=(x+1)%n
			y=(y-1)%n
			print(x,y)
			if (x==y):
				print("YES")
				flag=1
				break
		if flag==0:
			print("NO")

elif ((x-a)%n)>((y-b)%n):

	if (y>b):

		for i in range(y,b-1,-1):
			y=(y-1)%n
			x=(x+1)%n
			print(x,y)
			if (x==y):
				print("YES")
				flag=1
				break
		if flag==0:
			print("NO")

	elif (y<b):

		for i in range(y,y-b,-1):
			x=(x+1)%n
			y=(y-1)%n
			print(x,y)
			if (x==y):
				print("YES")
				flag=1
				break
		if flag==0:
			print("NO")


n=int(input())
n=n//2
l=list(map(int,input().split()))
l.sort()
sum1=0
sum2=0

for i in range(n):
	sum1=sum1+l[i]
	sum2=sum2+l[2*n-1-i]

if (sum1==sum2):
	print("-1")
else:
	for i in range(2*n):
		print(l[i],end=" ")


n=int(input())
l=list(map(int,input().split()))
c=0
l.sort()
while((sum(l[0:n]))==(sum(l[n:]))):
    a=l.pop(0)
    l.append(a)
    c=c+1
    if(c>=2*n+1):
        break
if(c>=2*n+1):
    print(-1)
else:
    print(*l)


n=int(input())
l=list(map(int,input().split()))
c=0
while((sum(l[0:n]))==(sum(l[n:]))):
    a=l.pop(0)
    l.append(a)
    c=c+1
    if(c>=2*n+1):
        break
if(c>=2*n+1):
    print(-1)
else:
    print(*l)


n=int(input())
l=list(map(int,input().split()))
c=0
while((sum(l[0:n]))==(sum(l[n:]))):
    a=l.pop(0)
    l.append(a)
    c=c+1
    if(c>=2*n):
        break
if(c>=2*n):
    print(-1)
else:
    print(*l)


n=int(input())
l=list(map(int,input().split()))
l.sort()
s1=sum(l[:n])
s2=sum(l[n::])
if s1==s2:
    print(-1)
else:
    print(" ".join(map(str,l)))


n = int(input())
a = list(map(int, input().split()))
s1 = 0
for i in range(n):
	s1 += a[i]
s2 = 0
for i in range(n, 2*n):
	s2 += a[i]
if s1 != s2:
	print(*a, sep=" ")
else:
	d1 = dict()
	for i in range(n):
		d1[a[i]] = i
	d2 = dict()
	for i in range(n, 2*n):
		d2[a[i]] = i
	if len(d1) > len(d2):
		d1, d2 = d2, d1
	x = list(d1.keys())[0]
	if x in d2:
		del d2[x]
	if d2:
		y = list(d2.keys())[0]
		i = d1[x]
		j = d2[y]
		a[i], a[j] = a[j], a[i]
		print(*a, sep=" ")
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[0] == a[-1]:
	print(-1)
else:
	print(*a, sep=" ")


n=int(input())
a=[int(i) for i in input().split()]
a.sort()
if  sum(a[:n])==sum(a[n:]):
    print(-1)
else:
    print(a)


n=int(input())
a=[int(i) for i in input().split()]
a.sort()
if  sum(a[:n])==sum(a[n:]):
    print(-1)
else:
    print(*a)


n=int(input())
ar=sorted(list(map(int,input().split())))
if ar[0:n]==ar[n:2*n]:
    print(-1)
else:
    print(*ar)


n=int(input())
ar=list(map(int,input().split()))
if ar==sorted(ar):
    print(-1)
else:
    ar=sorted(ar)
    print(*ar)


import sys
input = sys.stdin.readline
from collections import *

n = int(input())
a = list(map(int, input().split()))
a.sort()

if sum(a[:n])==sum(a[n:]):
    print(-1)
else:
    print(*a)


n=int(input())
l=sorted(map(int,input().split()))
if len(set(l))==1:
    print(-1)
else:
    print(*l)


n = int(input())
l = list(map(int, input().split()))
s = set(l)
f = len(s)
if f == 1:
    print(-1)
else:
    a = 0
    b = 0
    for i in range(n):
        a+=l[i]
        b+=l[n+i]
    if a == b:
        l.sort()
        # j = n
        # while j<2*n:
        #     if l[0] != l[j]:
        #         temp = l[0]
        #         l[0] = l[j]
        #         l[j] = temp
        #         break
        #     j+=1
    for i in range(2*n):
        print(l[i],end=' ')


n = int(input())
l = list(map(int, input().split()))
s = set(l)
f = len(s)
if f == 1:
    print(-1)
else:
    l.sort()
    for i in range(2*n):
        print(l[i],end=' ')


n = int(input())
l = list(map(int, input().split()))
s = set(l)
f = len(s)
if f == 1:
    print(-1)
else:
    j = n
    while j<2*n:
        if l[0] != l[j]:
            temp = l[0]
            l[0] = l[j]
            l[j] = temp
            break
        j+=1
    for i in range(2*n):
        print(l[i],end=' ')


n = int(input())
l = list(map(int, input().split()))
s = set(l)
f = len(s)
if f == 1:
    print(-1)
else:
    a = 0
    b = 0
    for i in range(n):
        a+=l[i]
        b+=l[n+i]
    if a == b:
        j = n
        while j<2*n:
            if l[0] != l[j]:
                temp = l[0]
                l[0] = l[j]
                l[j] = temp
                break
            j+=1
    for i in range(2*n):
        print(l[i],end=' ')


def call(n,a,flag,x,y):
	for i in range(n):
		for j in range(n,2*n):
			if x-a[i]+a[j]!=y+a[i]-a[j]:
				a[i],a[j]=a[j],a[i]
				for val in a:
					print(val, end=" ")
				print()
				flag=True
				return
	if flag==False:
		print(-1)

n=int(input())
a=list(map(int,input().split()))
x=sum(a[0:n])
y=sum(a[n:2*n])
flag=False
if x!=y:
	for val in a:
		print(val, end=" ")
	print()
	flag=True

else:
	call(n,a,flag,x,y)
	# for i in range(n):
	# 	for j in range(n,2*n):
	# 		if x-a[i]+a[j]!=y+a[i]-a[j]:
	# 			a[i],a[j]=a[j],a[i]
	# 			for val in a:
	# 				print(val, end=" ")
	# 			print()
	# 			flag=True
	# 		break
	# if flag==False:
	# 	print(-1)


n=int(input())
a=list(map(int,input().split()))
x=sum(a[0:n])
y=sum(a[n:2*n])
flag=False
if x!=y:
	for val in a:
		print(val, end=" ")
	print()
	flag=True

else:
	for i in range(n):
		for j in range(n,2*n):
			if x-a[i]+a[j]!=y+a[i]-a[j]:
				a[i],a[j]=a[j],a[i]
				for val in a:
					print(val, end=" ")
				print()
				flag=True
			break
	if flag==False:
		print(-1)


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

sorted(a)
ar=set(a)
if(len(ar)==1):
    print("-1")
else:
    print(*a, sep=' ')


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

a.sort()
ar=set(a)
if(len(ar)==1):
    print("-1")
else:
    print(*a, sep=' ')


n=int(input())
a=list(map(int,input().split()))
a.sort()
if(sum(a[:n])!=sum(a[n:])):
	print(*a)
else:
	print(-1)


def sint():
    return (int(input()))

def sara():
    return (list(map(int,input().split())))

def sstr():
    s = input()
    return (list(s[:len(s)]))

def sints():
    return (map(int, input().split()))

def solve():

    n = sint()

    ara = sara()
    flg = False

    for i in range(2*n-1):
        if ara[i] != ara[i+1]:
            flg = True
            break
    if flg:
        ara.sort()
        for i in ara:
            print(i, end=" ")
        print("")
    else:
        print(-1)

if __name__ == "__main__":

    solve()


n = int(input())
A = list(map(int,input().split()))
A.sort()
sum1=0;sum2=0
for i in range(n):
    sum1+=A[i]
    sum2+=A[i+n]
if(sum1==sum2):
    print("-1")
else:
    print(*A)


n=int(input())
a=[int(i) for i in input().split()]
d=set(a)
if(len(d)==1):
    print(-1)
else:
    print(*sorted(a))


n=int(input())
a=[int(i) for i in input().split()]
d=set(a)
c=0
for i in d:
    if(a.count(i)%2==0):
        c=c+1
if(c==len(d)):
    print(-1)
else:
    print(*sorted(a))


n=int(input())
a=list(map(int,input().split()))
a.sort()
if sum(a)==2*a[:n]:
    print(-1)
else:
    print(*a)


n=int(input())
a=list(map(int,input().split()))
a.sort()
if sum(a)==2*sum(a[:n]):
    print(-1)
else:
    print(*a)


n=int(input())
L=input().split()
L.sort()
if L[0]==L[-1]:
    print(-1)
else:
    print " ".join(L)


n=int(input())
L=input().split()
L.sort()
if L[0]==L[-1]:
    print(-1)
else:
    print (*L)


n=int(input())
L=input().split()
L.sort()
if L[0]=L[-1]:
    print(-1)
else:
    print " ".join(L)


n=int(input())
D={}
L=input().split()
for i in L:
    cle=int(i)
    if cle not in D:
        D[cle]=1
    else:
        D[cle]=D[cle]+1
if len(D.keys())==1:
    print(-1)
else:
    for i,j in D.items():
        for k in range(j):
            print(i,end=" ")


n=int(input())
a=list(map(int,input().split()))
s=set(a)
if len(s)==1:
	print(-1)
else:
	print(*sorted(a))


n=int(input())
a=list(map(int,input().split()))
s=set(a)
if len(s)==1:
	print(-1)
else:
	print(sorted(a))


n=int(input());l=list(map(int,input().split()));l.sort()
if sum(l[:n])!=sum(l[n:]):print(*l)
else:print(-1)


n = int(input())
lst = sorted(list(map(int,input().split())))

if sum(lst[:n]) == sum(lst[n:]):
    print(-1)
else:
    print(*lst)


import math
from collections import defaultdict, Counter, deque

INF = float('inf')

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while (i ** 2) <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	l = 2 * n
	arr = sorted(list(map(int, input().split())))

	if len(set(arr)) == 1: print(-1)
	else:
		print(arr)

if __name__ == "__main__":
	# t = int(input())
	t = 1
	for _ in range(t):
		main()


import math
from collections import defaultdict, Counter, deque

INF = float('inf')

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while (i ** 2) <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	l = 2 * n
	arr = sorted(list(map(int, input().split())))

	if len(set(arr)) == 1: print(-1)
	else:
		print(*arr)

if __name__ == "__main__":
	# t = int(input())
	t = 1
	for _ in range(t):
		main()


n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[0] == a[-1]:
	print(-1)
else:
	print(*a, sep=" ")


n= int(input())
a = list(map(int,input().split()))
b = set(a)
if (len(b)==1):
    print(-1)
    exit(0)
else:
    a = sorted(a)
for i in a:
    print(i, end=" ")


n= int(input())
a = list(map(int,input().split()))
b = set(a)
if (len(b)==1):
    print(-1)
else:
    a = sorted(a)
for i in a:
    print(i, end=" ")


n = int(input())
a = list(map(int,input().split()))
a.sort()
s1 = sum(a[:n])
s2 = sum(a[n:2*n])
if s1==s2:
    print(-1)
else:
    for x in a:
        print(x,end=" ")
    print()


# cook your dish here
# cook your dish here
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
import heapq
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))

def dict(a):
    d={}
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bi.bisect_right(a, x)
    if i != len(a):
        return i
    else:
        return -1

def main():
    try:
        n=I()
        l=list(In())
        l.sort()
        su,su1=0,0
        for x in range(n):
            su+=l[x]
        for x in range(n,2*n):
            su1+=l[x]
        q=0
        if su==su1:
            for x in range(n):
                if l[x]!=l[n-x-1]:
                    l[x],l[n-x-1]=l[n-x-1],l[x]
                    q=1
        if su!=su1:
            print(*l)
        else:
            if q==1:
                print(*l)
            else:
                print(-1)
    except:
        pass

M = 998244353
P = 1000000007

if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()


a=int(input())
l=sorted(map(int,input().split()))
print(' '.join(map(str,l))if sum(l[:a])!=sum(l[a:]) else -1)


n=int(input())
a=list(map(int,input().split()))
d1={};d2={}
if sum(a[:n])==sum(a[n:]):
    for i in range(n):
        d1[a[i]]=i
    for i in range(n,len(a)):
        d2[a[i]]=i
    flag=False
    for i in d1:
        if i not in d2 and not flag:
            pos=i
            flag=True
            break
    for i in d2:
        if i not in d1 and not flag:
            pos=i
            flag=True
            break
    if flag:
        if pos<n:
            a[pos],a[-1]=a[-1],a[pos]
        else:
            a[0],a[pos]=a[pos],a[0]
        print(*a)
    else:
        print(-1)
else:
    print(*a)


n=int(input())
a=list(map(int,input().split()))
if sum(a[:n])==sum(a[n:]):
    a.sort()
    if sum(a[:n])==sum(a[n:]):
        print(-1)
    else:
        print(*a)
else:
    print(*a)


n = int(input())
a = sorted([*map(int, input().split())])
if len(set(a))<=1:
    print(-1)
else:
    print(*a)


n = int(input())
a = [*map(int, input().split())]
print(*sorted(a) if len(set(a))!=1 else -1)


n=int(input())
num = list(map(int,input().split()))
d=set(num)
if len (d)==1:
    print(-1)
else:
    num.sort()
    print(*num)


import sys
input=sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from heapq import heapify, heappop, heappush
n=int(input())
l=list(map(int,input().split()))
if len(set(l))==1:
    print(-1)
else:
    print(*sorted(l))


from sys import stdin,stdout
from collections import Counter
def ai(): return list(map(int, stdin.readline().split()))
def ei(): return map(int, stdin.readline().split())
def ip(): return  int(stdin.readline().strip())
def op(ans): return stdout.write(str(ans) + '\n')

n = ip()
li = ai()
if len(set(li)) > 1:
	print(*sorted(li))
else:
	print(-1)


#!/usr/bin/env python3

x = int(input())
l = input().split()
for i in range(x+x):
    l[i] = int(l[i])

can = False
for i in range(1, x+x):
    if l[i] != l[0]:
        can = True
if not can:
    print(-1)
    exit(0)

sum1, sum2 = 0, 0
for i in l[:x]:
    sum1 += i
for i in l[x:]:
    sum2 += i

fl = False
if sum1 == sum2:
    for i in range(x):
        for j in range(x, x+x):
            if l[i] != l[j]:
                l[i], l[j] = l[j], l[i]
                fl = True
                break
            if fl:
                break
        if fl:
            break

o = []
for i in l:
    o.append(str(i))
print(" ".join(o))


#!/usr/bin/env python3

x = int(input())
l = input().split()
for i in range(x+x):
    l[i] = int(l[i])

can = False
for i in range(1, x+x):
    if l[i] != l[1]:
        can = True
if not can:
    print(-1)
    exit(0)

sum1, sum2 = 0, 0
for i in l[:x]:
    sum1 += i
for i in l[x:]:
    sum2 += i

fl = False
if sum1 == sum2:
    for i in range(x):
        for j in range(x, x+x):
            if l[i] != l[j]:
                l[i], l[j] = l[j], l[i]
                fl = True
                break
            if fl:
                break
        if fl:
            break

o = []
for i in l:
    o.append(str(i))
print(" ".join(o))


import itertools

n = int(input())
ar = list(map(int,input().split()))
good = False
subsets = list(itertools.combinations(ar,n))
for e in subsets:
	for f in subsets:
		if sum(e) != sum(f) and sorted(e+f) == sorted(ar):
			good = True
			res = e + f
			break
print(*res if good else '-1')


import itertools

n = int(input())
ar = list(map(int,input().split()))
good = False
subsets = list(itertools.combinations(ar,n))
for e in subsets:
	for f in subsets:
		if sum(e) != sum(f):
			good = True
			res = e + f
			break
print(*res if good else '-1')


n = int(input())
ar = list(map(int,input().split()))
if len(set(ar)) < 2:
	print('-1')
else:
	print(*sorted(ar))


n=int(input())
m=list(map(int,input().strip().split()))
m.sort()
if sum(m[:n])==sum(m[n:]):print(-1)
else:print(*m)


n = int(input())
a = [int(i) for i in input().split()]
if len(set(a)) <= 1:
    print(-1)
else:
    for i in range(n):
        if sum(a[:n]) == sum(a[n:]):
            for j in range(n):
                if a[i] != a[n + j]:
                    a[i], a[n + j] = a[n + j], a[i]
                    break
        else:
            break
    print(' '.join([str(i) for i in a]))


n = int(input())
a = [int(i) for i in input().split()]
if len(set(a)) <= 1:
    print(-1)
else:
    if sum(a[:n]) == sum(a[n:]):
        for i in range(n):
            if a[i] != a[n + i]:
                a[i], a[n + i] = a[n + i], a[i]
    print(' '.join([str(i) for i in a]))


n = int(input())
a = [int(i) for i in input().split()]
if len(set(a)) <= 1:
    print(-1)
else:
    if sum(a[:n]) == sum(a[n:]):
        for i in range(n):
            if a[i] != a[n + i]:
                a[i], a[n + i] = a[n + i], a[i]
                break
    print(' '.join([str(i) for i in a]))


n = int(input())

nums = list(map(int, input().split()))
nums.sort()
if sum(nums[:n]) != sum(nums[n:]):
    res = ''
    for i, num in enumerate(nums):
        res += str(num)
        if i < 2 * n - 1:
            res += ' '
    print(res)
else:
    print(-1)


n = int(input())
x = list(map(int, input().split()))
if sum(x[:n]) != sum(x[n:]):
    print(*x)
else:
    x.sort()
    if sum(x[:n]) != sum(x[n:]):
        print(*x)
    else:
        print(-1)


n = int(input())
x = list(map(int, input().split()))
if sum(x[:n]) != sum(x[n:]):
    print(*x)
else:
    for i in range(n):
        if x[n - 1 - i] != x[n + i]:
            x[n - 1 - i], x[n + i] = x[n + i], x[n - 1 - i]
            print(*x)
            break
        elif i == n - 1:
            print(-1)


n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    if x[n - 1 - i] != x[n + i]:
        x[n - 1 - i], x[n + i] = x[n + i], x[n - 1 - i]
        print(*x)
        break
    elif i == n - 1:
        print(-1)


from sys import stdin,stdout
get=stdin.readline;put=stdout.write
n,a=int(get()),sorted(list(map(int,get().split())))
print(a if a[n:]!=a[:n] else -1)


from sys import stdin,stdout
get=stdin.readline;put=stdout.write
n,a=int(get()),sorted(list(map(int,get().split())))
print(*a if a[n:]!=a[:n] else -1)


from sys import stdin,stdout
get=stdin.readline;put=stdout.write
n=int(get());a=sorted(list(map(int,get().split())))
print(*a if a[n:]!=a[:n] else [-1])


if __name__ == "__main__":
    data = []
    n = int(input())
    data[:] = map(int, input().split())
    data.sort()
    f = 1
    for i in range(0, 2*n, 2):
        if data[i] != data[i+1]:
            f = 0
    if f == 1:
        print(-1)
    else:
        for i in range(0, 2*n, 2):
            print(data[i], end=' ')
        for i in range(1, 2*n, 2):
            print(data[i], end=' ')


if __name__ == "__main__":
    data = []
    n = int(input())
    data[:] = map(int, input().split())
    f = 1
    for i in range(2*n-1):
        if data[i] != data[i+1]:
            f = 0
    if f:
        print(-1)
    else:
        data.sort()
        for i in data:
            print(i, end=' ')


def change_arr(l: list, n: int):
    if sum(l[:n]) != sum(l[n:]):
        return l

    for i in range(n):
        for j in range(n):
            if l[i] != l[j+n]:
                l[i], l[j+n] = l[j+n], l[i]
                return l
    return [-1,]

n = int(input())
l = list(map(lambda x: int(x), input().split()))
print(*change_arr(l, n))


def change_arr(l: list, n: int):
    if sum(l[:n]) != sum(l[n:]):
        return l

    for i in range(n):
        if l[i] != l[i+n]:
            l[i], l[i+n] = l[i+n], l[i]
            return l
    return [-1,]

n = int(input())
l = list(map(lambda x: int(x), input().split()))
print(*change_arr(l, n))


n=int(input())
arr=list(map(int,input().split()))
if sum(arr[:len(arr)//2])!=sum(arr[len(arr)//2:]):
    print(arr)
else:
    arr.sort()
    if sum(arr[:len(arr)//2])!=sum(arr[len(arr)//2:]):
        print(arr)
    else:
        print(-1)


n=int(input())
arr=list(map(int,input().split()))
if sum(arr[:len(arr)//2])!=sum(arr[len(arr)//2:]):
    print(*arr)
else:
    arr.sort()
    if sum(arr[:len(arr)//2])!=sum(arr[len(arr)//2:]):
        print(*arr)
    else:
        print(-1)


n = int(input())
l = sorted(list(map(int,input().split(" "))))
if sum(l[:n]) != sum(l[n:]): print(*l)
else: print(-1)


n=int(input())
l1=list(map(int,input().split()))
l1.sort()
if(sum(l1[:n])==sum(l1[n:])):
    print(-1)
else:
    for i in range (len(l1)):
        print(l1[i],end=" ")


n=int(input())
l=list(map(int,input().split()))
d=[]
for i in range(2*n):
    d.append(l[i])
l.sort()
if(l==d):
    print(-1)
else:
    print(*l)


n=int(input())
l=list(map(int,input().split()))
m=len(set(l))
l.sort()
if(m==1):
    print(-1)
else:
    print(*l)


n = int(input())

L = list(map(int, input().split()))

if sum(L[:n]) == sum(L[n:]) and min(L[:n]) == max(L[n:]):
    print(-1)
elif sum(L[:n]) != sum(L[n:]):
    print(" ".join(map(str, L)))
else:
    pos1 = L[:n].index(min(L[:n]))
    pos2 = L[n:].index(max(L[n:]))+n
    L[pos1], L[pos2] = L[pos2], L[pos1]

    print(' '.join(map(str, L)))


n = int(input())

L = list(map(int, input().split()))

if sum(L[:n]) == sum(L[n:]) and min(L[:n]) == max(L[n:]):
    print(-1)

else:
    pos1 = L[:n].index(min(L[:n]))
    pos2 = L[n:].index(max(L[n:]))+n
    L[pos1], L[pos2] = L[pos2], L[pos1]

    print(' '.join(map(str, L)))


n = int(input())
d = [int(i) for i in input().split()]
a = set(d )
if len(a)>1:
    print(' '.join([str(i) for i in sorted(a)]))
else:
    print(-1)


#include<bits/stdc++.h>
#define int         int64_t
#define loop(i, a, n) for (int i = a; i < int(n); ++i)
#define loop_rev(i, n, a) for (int i = int(n) - 1; i >= int(a); --i)
#define all(x) (x).begin(),(x).end()
#define pb          push_back
#define ii         pair<int,int>
#define vi          vector< int>
#define iii			tuple<int,int,int>
#define iiii		tuple<int,int,int,int>
#define ST			get<0>
#define ND			get<1>
#define RD			get<2>
#define TH			get<3>
#define pi			3.141592653589793238462
#define double      long double
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define x			first
#define y			second

using namespace std;
int mod = 1000000007, inf = 4e18;
int n,m;
void dfs(vector<vector<bool>>  & mat, vector<vi>& cnt, int i, int j)
{
    if(i<0 || i>=n-1 || j<0 || j>=m-1) return;
    cnt[i][j]++;
    if(cnt[i][j]>=4) return;
    if(cnt[i][j]==3)
    {
        if(mat[i][j]==0)
        {
            mat[i][j]=1;
            dfs(mat,cnt,i-1,j-1);
            dfs(mat,cnt,i-1,j);
            dfs(mat,cnt,i,j-1);
        }
        if(mat[i+1][j]==0)
        {
            mat[i+1][j]=1;
            dfs(mat,cnt,i+1,j);
            dfs(mat,cnt,i+1,j-1);
            dfs(mat,cnt,i,j-1);
        }
        if(mat[i][j+1]==0)
        {
            mat[i][j+1]=1;
            dfs(mat,cnt,i,j+1);
            dfs(mat,cnt,i-1,j+1);
            dfs(mat,cnt,i-1,j);
        }
        if(mat[i+1][j+1]==0)
        {
            mat[i+1][j+1]=1;
            dfs(mat,cnt,i+1,j+1);
            dfs(mat,cnt,i+1,j);
            dfs(mat,cnt,i,j+1);
        }
    }
}

int32_t main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr); cout << fixed << setprecision(0);
    cin>>n>>m;
    vector<vector<bool>> mat(n, vector<bool>(m,0));
    vector<vi> cnt(n-1,vi(m-1,0));
    char c;
    loop(i,0,n) loop(j,0,m)
    {
        cin>>c;
        mat[i][j]=(c=='.');
        if(c=='.')
        {
            if(i && j) cnt[i-1][j-1]++;
            if(i && j<m-1) cnt[i-1][j]++;
            if(i<n-1 && j) cnt[i][j-1]++;
            if(i<n-1 && j<n-1) cnt[i][j]++;
        }
    }
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<m-1;j++)
        {
            if(cnt[i][j]==3) cnt[i][j]=2, dfs(mat,cnt,i,j);
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) cout<<(mat[i][j]?'.':'*');
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define int         int64_t
#define loop(i, a, n) for (int i = a; i < int(n); ++i)
#define loop_rev(i, n, a) for (int i = int(n) - 1; i >= int(a); --i)
#define all(x) (x).begin(),(x).end()
#define pb          push_back
#define ii         pair<int,int>
#define vi          vector< int>
#define iii			tuple<int,int,int>
#define iiii		tuple<int,int,int,int>
#define ST			get<0>
#define ND			get<1>
#define RD			get<2>
#define TH			get<3>
#define pi			3.141592653589793238462
#define double      long double
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define x			first
#define y			second

using namespace std;
int mod = 1000000007, inf = 4e18;
int n,m;
void dfs(vector<vector<bool>>  & mat, vector<vi>& cnt, int i, int j)
{
    if(i<0 || i>=n-1 || j<0 || j>=m-1) return;
    cnt[i][j]++;
    if(cnt[i][j]>=4) return;
    if(cnt[i][j]==3)
    {
        if(mat[i][j]==0)
        {
            mat[i][j]=1;
            dfs(mat,cnt,i-1,j-1);
            dfs(mat,cnt,i-1,j);
            dfs(mat,cnt,i,j-1);
        }
        if(mat[i+1][j]==0)
        {
            mat[i+1][j]=1;
            dfs(mat,cnt,i+1,j);
            dfs(mat,cnt,i+1,j-1);
            dfs(mat,cnt,i,j-1);
        }
        if(mat[i][j+1]==0)
        {
            mat[i][j+1]=1;
            dfs(mat,cnt,i,j+1);
            dfs(mat,cnt,i-1,j+1);
            dfs(mat,cnt,i-1,j);
        }
        if(mat[i+1][j+1]==0)
        {
            mat[i+1][j+1]=1;
            dfs(mat,cnt,i+1,j+1);
            dfs(mat,cnt,i+1,j);
            dfs(mat,cnt,i,j+1);
        }
    }
}

int32_t main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr); cout << fixed << setprecision(0);
    cin>>n>>m;
    vector<vector<bool>> mat(n, vector<bool>(m,0));
    vector<vi> cnt(n-1,vi(m-1,0));
    char c;
    loop(i,0,n)
    loop(j,0,m)
    {
        cin>>c;
        mat[i][j]=(c=='.');
        if(c=='.')
        {
            if(i && j) cnt[i-1][j-1]++;
            if(i && j<m-1) cnt[i-1][j]++;
            if(i<n-1 && j) cnt[i][j-1]++;
            if(i<n-1 && j<m-1) cnt[i][j]++;
        }
    }
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<m-1;j++)
        {
            if(cnt[i][j]==3) cnt[i][j]=2, dfs(mat,cnt,i,j);
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) cout<<(mat[i][j]?'.':'*');
        cout<<endl;
    }
    return 0;
}


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

#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))

const int MAXN = 2e3+10;
char mps[MAXN][MAXN];
int dx[] = {0,1,1,0};
int dy[] = {1,1,0,0};
int n, m;
void dfs(int x, int y)
{
    if(x<0 || x>=n-1 || y<0 || y>=m-1) return;
    int res = 0;
    int fx, fy;
    for(int i = 0; i < 4; i++) {
        int xx = x+dx[i];
        int yy = y+dy[i];
        if(mps[xx][yy] == '*') {
            res++;
            fx = xx; fy = yy;
        }
    }
    if(res == 1) {
        mps[fx][fy] ='.';
        for(int i = -1; i <= 1; i++) {
            for(int j = -1; j <= 1; j++) {
                 dfs(fx+i,fy+j);
            }
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 0; i < n; i++)
        scanf("%s",mps[i]);
    for(int i = 0; i < n-1; i++) {
        for(int j = 0;j < m-1; j++) {
            dfs(i,j);
        }
    }
    for(int i = 0; i < n; i++)
        printf("%s\n",mps[i]);
return 0;
}


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

#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a)
int dx[] = {0,1,1,0};
int dy[] = {1,1,0,0};
int n, m;
void dfs(char mps[2000][2000],int x, int y)
{
    if(x<0 || x>=n-1 || y<0 || y>=m-1) return;
    int res = 0;
    int fx, fy;
    for(int i = 0; i < 4; i++) {
        int xx = x+dx[i];
        int yy = y+dy[i];
        if(mps[xx][yy] == '*') {
            res++;
            fx = xx; fy = yy;
        }
    }
    if(res == 1) {
        mps[fx][fy] ='.';
        for(int i = -1; i <= 1; i++) {
            for(int j = -1; j <= 1; j++) {
                 dfs(fx+i,fy+j);
            }
        }
    }
}
int main()
{
    int idx, jdx;
    int n, m;
    cin >> n >> m;
    char nm[2000][2000];

    for(idx=0;idx<n;idx++){
        for(idj =0 idx < m; idj++){
            cin>>nm[idx][jdx];
        }
    }
    for(int i = 0; i < n-1; i++) {
        for(int j = 0;j < m-1; j++) {
            dfs(nm,i,j);
        }
    }
    for(int i = 0; i < n; i++)
        printf("%s\n",nm[i]);
return 0;
}


/*

*/
#include <bits/stdc++.h>
#define md(x, y)  ((x + y) >> 1)
#define ls(x)      (x << 1)
#define rs(x)      (x << 1 | 1)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e3 + 10;
int a[MAXN][MAXN];
char s[MAXN][MAXN];
int n, m;
bool ok(int x, int y)
{
    int dx = x + 1, dy = y + 1;
    if(x < 1 || y < 1 || dx < 1 || dy < 1 || x > n || y > m || dx > n || dy > m) return false;
    return true;
}
bool check(int x, int y)
{
    if(!ok(x, y)) return false;
    int cnt = 0;
    for(int i = x; i <= x + 1; i++)
        for(int j = y; j <= y + 1; j++)
            if(a[i][j]) cnt++;
    if(cnt == 3) return true;
    else    return false;
}
int dir[4][2] = {0, 0, -1, -1, -1, 0, 0, -1};
void dfs(int x, int y)
{
    if(a[x][y]) return; //已经是平地了
    if(!check(x, y) && !check(x - 1, y - 1) && !check(x - 1, y) && !check(x, y - 1)) return;
    a[x][y] = 1;
    for(int z = 0; z < 4; z++)
    {
        int dx = x + dir[z][0];
        int dy = y + dir[z][1];
        if(!ok(dx, dy)) continue;
        for(int i = dx; i <= dx + 1; i++)
            for(int j = dy; j <= dy + 1; j++)
                if(!a[i][j])
                    dfs(i, j);
    }
}
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        scanf("%s", s[i] + 1);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            a[i][j] = s[i][j] == '.';   //1表示平地

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(!a[i][j])
                dfs(i, j);

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
            if(a[i][j])
                cout << '.';
            else
                cout << '*';
        cout << endl;
    }
    return 0;
}


/*

*/
#include <bits/stdc++.h>
#define md(x, y)  ((x + y) >> 1)
#define ls(x)      (x << 1)
#define rs(x)      (x << 1 | 1)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e3 + 10;
int a[MAXN][MAXN];
char s[MAXN][MAXN];
int n, m;
bool check(int x, int y)
{
    int dx = x + 1, dy = y + 1;
    if(x < 1 || y < 1 || dx < 1 || dy < 1 || x > n || y > m || dx > n || dy > m) return false;
    int cnt = 0;
    for(int i = x; i <= dx; i++)
        for(int j = y; j <= dy; j++)
            if(a[i][j]) cnt++;
    if(cnt == 3) return true;
}
int dir[4][2] = {0, 0, -1, -1, -1, 0, 0, -1};
void dfs(int x, int y)
{
    if(a[x][y]) return; //已经是平地了
    if(!check(x, y) && !check(x - 1, y - 1) && !check(x - 1, y) && !check(x, y - 1)) return;
    a[x][y] = 1;
    for(int z = 0; z < 4; z++)
    {
        int dx = x + dir[z][0];
        int dy = y + dir[y][0];
        if(dx < 1 || dy < 1 || dx > n || dy > m) continue;
        for(int i = dx; i <= dx + 1; i++)
            for(int j = dy; j <= dy + 1; j++)
            {
                if(i < 1 || j < 1 || i > n || j > m) continue;
                if(!a[i][j])
                    dfs(i, j);
            }
    }
}
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        scanf("%s", s[i] + 1);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            a[i][j] = s[i][j] == '.';   //1表示平地

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(!a[i][j])
                dfs(i, j);

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
            if(a[i][j])
                cout << '.';
            else
                cout << '*';
        cout << endl;
    }
    return 0;
}


/*

*/
#include <bits/stdc++.h>
#define md(x, y)  ((x + y) >> 1)
#define ls(x)      (x << 1)
#define rs(x)      (x << 1 | 1)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e3 + 10;
int a[MAXN][MAXN];
char s[MAXN][MAXN];
int n, m;
bool check(int x, int y)
{
    int dx = x + 1, dy = y + 1;
    if(x < 1 || y < 1 || dx < 1 || dy < 1 || x > n || y > m || dx > n || dy > m) return false;
    int cnt = 0;
    for(int i = x; i <= dx; i++)
        for(int j = y; j <= dy; j++)
            if(a[i][j]) cnt++;
    if(cnt == 3) return true;
    else    return false;
}
int dir[4][2] = {0, 0, -1, -1, -1, 0, 0, -1};
void dfs(int x, int y)
{
    if(a[x][y]) return; //已经是平地了
    if(!check(x, y) && !check(x - 1, y - 1) && !check(x - 1, y) && !check(x, y - 1)) return;
    a[x][y] = 1;
    for(int z = 0; z < 4; z++)
    {
        int dx = x + dir[z][0];
        int dy = y + dir[y][0];
        if(dx < 1 || dy < 1 || dx > n || dy > m) continue;
        for(int i = dx; i <= dx + 1; i++)
            for(int j = dy; j <= dy + 1; j++)
            {
                if(i < 1 || j < 1 || i > n || j > m) continue;
                if(!a[i][j])
                    dfs(i, j);
            }
    }
}
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        scanf("%s", s[i] + 1);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            a[i][j] = s[i][j] == '.';   //1表示平地

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(!a[i][j])
                dfs(i, j);

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
            if(a[i][j])
                cout << '.';
            else
                cout << '*';
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, m, ans;
char sir[2005][2005];
/*struct punct{
    int x, y;
}ant[]={{0,0},{-1,-1},{-1,0},{-1,1},{0,-1}};*/
void digdugdug(int i, int j){
    if((i<1)||(i>n)) return;
    if((j<1)||(j>m)) return;
    int cnt=0;
    for(int x=0; x<=1;x++)
        for(int y=0; y<=1; y++)
            cnt+=(sir[i+x][j+y]=='*');
    if(cnt==1){
        for(int x=0; x<=1;x++)
            for(int y=0; y<=1; y++)
                sir[i+x][j+y]='.';
          for(int x=-1; x<=1;x++)
             for(int y=-1; y<=1; y++)
                  digdugdug(i+x, j+y);
    }
}
int main(){

    int i, j;
    cin>>n>>m;
    for(i=1; i<=n; i++)
        cin>>(sir[i]+1);
    for(i=1; i<n; i++)
        for(j=1; j<m; j++)
            digdugdug(i,j);
    for(i=1; i<=n; i++){
       for(j=1; j<=m; j++)
           cout<<sir[i][j];
       cout<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, m, ans;
char sir[2005][2005];
/*
4 4
****
*..*
*...
***.
*/
void digdugdug(int i, int j){
    if((i<1)||(i>=n)) return; //!
    if((j<1)||(j>=m)) return; //!
    int cnt=0;
    for(int x=0; x<=1;x++)
        for(int y=0; y<=1; y++)
            cnt+=(sir[i+x][j+y]=='*');
    if(cnt==1){
        for(int x=0; x<=1;x++)
            for(int y=0; y<=1; y++)
                sir[i+x][j+y]='.';
          for(int x=-1; x<=1;x++)
             for(int y=-1; y<=1; y++)
                  digdugdug(i+x, j+y);
    }
}
int main(){

    int i, j;
    cin>>n>>m;
    for(i=1; i<=n; i++)
        cin>>(sir[i]+1);
    for(i=1; i<n; i++)
        for(j=1; j<m; j++)
            digdugdug(i,j);
    for(i=1; i<=n; i++){
       for(j=1; j<=m; j++)
           cout<<sir[i][j];
       cout<<"\n";
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int n,m,x1,y1,x2,y2,f[5000],i,j;
multiset<pair<int, pair<int, int> > > s;
pair<int, pair<int, int> > p;
bool used[2000][2000];
char a[2000][2000];
void dfs(int x, int y){
    if(x < 0 || y < 0 || x >= n || y >= m)
        return;
    if(used[x][y] || a[x][y] == '*') return;
    used[x][y] = true;
    x1 = min(x1, x); y1 = min(y1, y);
    x2 = max(x2, x); y2 = max(y2, y);
    dfs(x + 1, y); dfs(x - 1, y);
    dfs(x, y + 1); dfs(x, y - 1);
}
void update(int x, int d){
    for(int i = x; i < m; i |= i + 1)
        f[i] += d;
}
int get(int x){
    int i, sum = 0;
    for(i = x; i >= 0; i = (i&(i + 1)) - 1)
        sum += f[i];
    return sum;
}
int main(){
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++)
            cin >> a[i][j];
    }
    for(i = 0; i < n; i++){
        while(!s.empty() && s.begin() -> first == i){
            p = *s.begin();
            update(p.second.first, -1);
            update(p.second.second + 1, 1);
            s.erase(s.begin());
        }
        for(j = 0; j < m; j++){
            if(a[i][j] != '*'){
                if(!used[i][j]){
                    x1 = x2 = i;
                    y1 = y2 = j;
                    dfs(i, j);
                    s.insert(make_pair(x2 + 1, make_pair(y1, y2)));
                    update(y1, 1); update(y2 + 1, -1);
                }
            }
        }
        for(j = 0; j < m; j++){
            if(a[i][j] == '*'){
                if(get(j)) cout << '.';
                else cout << '*';
            }
            else cout << '.';
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#define DIM 2010
using namespace std;
char a[DIM][DIM];bool viz[DIM][DIM];
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,m,xmax,ymax;
bool square(int i,int j) {
    if (a[i][j]!='*') return 0;
    if (a[i+1][j]!='.') return 0;
    if (a[i][j+1]!='.') return 0;
    if (a[i+1][j+1]!='.') return 0;
    return 1;
}
bool inside(int i,int j) {
    if (i<1 || i>n) return 0;
    if (j<1 || j>m) return 0;
    return 1;
}
void umple(int i,int j) {
    viz[i][j]=1;
    for (int p=0;p<4;++p) {
        int x=i+dx[p],y=j+dy[p];
        if (inside(x,y)) if (!viz[x][y] && a[x][y]=='.')
              xmax=max(xmax,i),ymax=max(ymax,j),umple(x,y);
    }
}
void vecin(int i,int j) {
    a[i][j]='.';
    if (inside(i-1,j-1)) if (square(i-1,j-1)) vecin(i-1,j-1);
    if (inside(i-1,j)) if (square(i-1,j)) vecin(i-1,j);
    if (inside(i,j-1)) if (square(i,j-1)) vecin(i,j-1);
}
int main()
{   int i,j;
    cin>>n>>m;
    for (i=1;i<=n;++i)
    for (j=1;j<=m;++j)
        cin>>a[i][j];

    for (i=0;i<=n+1;++i)
       a[i][0]=a[i][m+1]='.';
    for (j=0;j<=m+1;++j)
       a[0][j]=a[n+1][j]='.';

    for (i=1;i<=n;++i)
    for (j=1;j<=m;++j)
        if (square(i,j)) vecin(i,j);

    for (i=1;i<=n;++i)
    for (j=1;j<=m;++j)
       if (!viz[i][j] && a[i][j]=='.') {
           xmax=i,ymax=j;
            umple(i,j);
          for (int l=i;l<=xmax;++l)
          for (int c=j;c<=ymax;++c)
              a[l][c]='.';
       }

      for (i=1;i<=n;++i) {
      for (j=1;j<=m;++j)
          cout<<a[i][j];
        cout<<'\n';
      }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, m;
char grid[2020][2020], s[2020];

bool check(int i, int j) {
    if(grid[i][j] == '.') return false;
    if(grid[i-1][j] == '.' && grid[i-1][j-1] == '.' && grid[i][j-1] == '.')
        grid[i][j] = '.';
    else if(grid[i-1][j] == '.' && grid[i-1][j+1] == '.' && grid[i][j+1] == '.')
        grid[i][j] = '.';
    else if(grid[i+1][j] == '.' && grid[i+1][j+1] == '.' && grid[i][j+1] == '.')
        grid[i][j] = '.';
    else if(grid[i+1][j] == '.' && grid[i+1][j-1] == '.' && grid[i][j-1] == '.')
        grid[i][j] = '.';
    else return false;
    return true;
}

int main() {
    scanf("%d %d", &n, &m);

    memset(grid, '*', sizeof grid);
    for(int i = 1; i <= n; i++) {
        scanf("%s", s + 1);
        for(int j = 1; j <= m; j++)
            grid[i][j] = s[j];
    }

    queue<pair<int, int> > fila;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(check(i, j))
                fila.push({i, j});

    while(!fila.empty()) {
        auto p = fila.front(); fila.pop();
        for(int i = p.first - 1; i <= p.first + 1; i++)
            for(int j = p.second - 1; j <= p.second + 1; j++)
                if(check(i, j))
                    fila.push({i, j});
    }

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++)
            printf("%c", grid[i][j]);
        puts("");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int p[N * N];
int Lx[N * N], Ly[N * N], Rx[N * N], Ry[N * N];;
int f(int x) {
	return x == p[x] ? x : p[x] = f(p[x]);
}

void join(int i, int j, int ii, int jj) {
	int u = f(ii * N + jj);
	int v = f(i * N + j);
	if(u == v) return;
	p[v] = u;
	Lx[u] = min(Lx[u], Lx[v]);
	Ly[u] = min(Ly[u], Ly[v]);
	Rx[u] = max(Rx[u], Rx[v]);
	Ry[u] = max(Ry[u], Ry[v]);
}

int n, m;
char s[N][N];
int mat[N][N];

set<int> pos[N];

int main() {

	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf(" %s", s[i] + 1);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			p[i * N + j] = i * N + j;
			Lx[i * N + j] = Rx[i * N + j] = i;
			Ly[i * N + j] = Ry[i * N + j] = j;
			if(s[i][j] == '*') continue;
			if(s[i - 1][j] == '.') join(i, j, i-1, j);
			if(s[i][j - 1] == '.') join(i, j, i, j-1);
		}
	}

	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
		if(s[i][j] == '*') {
			pos[i].insert(j);
		}
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
		if(s[i][j] == '*') continue;
		int u = i * N + j;
		if(f(u) == u) q.push(u);
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		int i = u / N, j = u % N;
		bool rep = false;
		for(int x = Lx[u]; x <= Rx[u]; x++) {
			auto it = pos[x].lower_bound(Ly[u]);
			while(it != pos[x].end() and *it <= Ry[u]) {
				int y = *it;
				s[x][y] = '.';
				rep = true;
				if(s[x - 1][y] == '.') join(x, y, x-1, y);
				if(s[x][y - 1] == '.') join(x, y, x, y-1);
				if(s[x + 1][y] == '.') join(x, y, x+1, y);
				if(s[x][y + 1] == '.') join(x, y, x, y+1);

				it = pos[x].erase(it);
			}
		}
		if(rep) q.push(f(u));
	}

	for(int i = 1; i <= n; i++) {
		printf("%s\n", s[i] + 1);
	}

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int p[N * N];
int Lx[N * N], Ly[N * N], Rx[N * N], Ry[N * N];;
int f(int x) {
	return x == p[x] ? x : p[x] = f(p[x]);
}

void join(int i, int j, int ii, int jj) {
	int u = f(ii * N + jj);
	int v = f(i * N + j);
	if(u == v) return;
	p[v] = u;
	Lx[u] = min(Lx[u], Lx[v]);
	Ly[u] = min(Ly[u], Ly[v]);
	Rx[u] = max(Rx[u], Rx[v]);
	Ry[u] = max(Ry[u], Ry[v]);
}

int n, m;
char s[N][N];
int mat[N][N];

int main() {

	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf(" %s", s[i] + 1);

	while(1) {
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				mat[i][j] = 0;
				if(s[i][j] == '*') continue;
				p[i * N + j] = i * N + j;
				Lx[i * N + j] = Rx[i * N + j] = i;
				Ly[i * N + j] = Ry[i * N + j] = j;
				if(s[i - 1][j] == '.') join(i, j, i-1, j);
				if(s[i][j - 1] == '.') join(i, j, i, j-1);
			}
		}

		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
			if(s[i][j] == '*') continue;
			int u = i * N + j;
			if(f(u) != u) continue;
			mat[ Lx[u] ][ Ly[u] ]++;
			mat[ Rx[u]+1 ][ Ly[u] ]--;
			mat[ Lx[u] ][ Ry[u]+1 ]--;
			mat[ Rx[u]+1 ][ Ry[u]+1 ]++;
		}
		bool rep = false;
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
			mat[i][j] += mat[i][j-1] + mat[i-1][j] - mat[i-1][j-1];
			if(mat[i][j] and s[i][j] == '*') {
				s[i][j] = '.';
				rep = true;
			}
		}
		if(!rep) break;
	}

	for(int i = 1; i <= n; i++) {
		printf("%s\n", s[i] + 1);
	}

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int p[N * N];
int Lx[N * N], Ly[N * N], Rx[N * N], Ry[N * N];;
int f(int x) {
	return x == p[x] ? x : p[x] = f(p[x]);
}

void join(int i, int j, int ii, int jj) {
	int u = f(ii * N + jj);
	int v = f(i * N + j);
	if(u == v) return;
	p[v] = u;
	Lx[u] = min(Lx[u], Lx[v]);
	Ly[u] = min(Ly[u], Ly[v]);
	Rx[u] = max(Rx[u], Rx[v]);
	Ry[u] = max(Ry[u], Ry[v]);
}

int n, m;
char s[N][N];
int mat[N][N];

int main() {

	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf(" %s", s[i] + 1);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			p[i * N + j] = i * N + j;
			Lx[i * N + j] = Rx[i * N + j] = i;
			Ly[i * N + j] = Ry[i * N + j] = j;
			if(s[i][j] == '*') continue;
			if(s[i - 1][j] == '.') join(i, j, i-1, j);
			if(s[i][j - 1] == '.') join(i, j, i, j-1);
		}
	}

	while(1) {
		memset(mat, 0, sizeof mat);
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
			if(s[i][j] == '*') continue;
			int u = i * N + j;
			if(f(u) != u) continue;
			mat[ Lx[u] ][ Ly[u] ]++;
			mat[ Rx[u]+1 ][ Ly[u] ]--;
			mat[ Lx[u] ][ Ry[u]+1 ]--;
			mat[ Rx[u]+1 ][ Ry[u]+1 ]++;
		}
		bool rep = false;
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
			mat[i][j] += mat[i][j-1] + mat[i-1][j] - mat[i-1][j-1];
			if(mat[i][j] and s[i][j] == '*') {
				s[i][j] = '.';
				rep = true;
				if(s[i - 1][j] == '.') join(i, j, i-1, j);
				if(s[i][j - 1] == '.') join(i, j, i, j-1);
				if(s[i + 1][j] == '.') join(i, j, i+1, j);
				if(s[i][j + 1] == '.') join(i, j, i, j+1);
			}
		}
		if(!rep) break;
	}

	for(int i = 1; i <= n; i++) {
		printf("%s\n", s[i] + 1);
	}

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int p[N * N];
int Lx[N * N], Ly[N * N], Rx[N * N], Ry[N * N];;
int f(int x) {
	return x == p[x] ? x : p[x] = f(p[x]);
}

void join(int i, int j, int ii, int jj) {
	int u = f(ii * N + jj);
	int v = f(i * N + j);
	if(u == v) return;
	p[v] = u;
	Lx[u] = min(Lx[u], Lx[v]);
	Ly[u] = min(Ly[u], Ly[v]);
	Rx[u] = max(Rx[u], Rx[v]);
	Ry[u] = max(Ry[u], Ry[v]);
}

int n, m;
char s[N][N];
int mat[N][N];

set<int> pos[N];

int d[N*N];

int main() {

	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf(" %s", s[i] + 1);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			p[i * N + j] = i * N + j;
			Lx[i * N + j] = Rx[i * N + j] = i;
			Ly[i * N + j] = Ry[i * N + j] = j;
			if(s[i][j] == '*') continue;
			if(s[i - 1][j] == '.') join(i, j, i-1, j);
			if(s[i][j - 1] == '.') join(i, j, i, j-1);
		}
	}

	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
		if(s[i][j] == '*') {
			pos[i].insert(j);
		}
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
		if(s[i][j] == '*') continue;
		int u = i * N + j;
		if(f(u) == u) q.push(u), d[u]++;
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(f(u) != u) continue;
		d[u]--;
		if(d[u]) continue;
		int i = u / N, j = u % N;
		bool rep = false;
		for(int x = Lx[u]; x <= Rx[u]; x++) {
			auto it = pos[x].lower_bound(Ly[u]);
			while(it != pos[x].end() and *it <= Ry[u]) {
				int y = *it;
				s[x][y] = '.';
				rep = true;
				if(s[x - 1][y] == '.') join(x, y, x-1, y);
				if(s[x][y - 1] == '.') join(x, y, x, y-1);
				if(s[x + 1][y] == '.') join(x, y, x+1, y);
				if(s[x][y + 1] == '.') join(x, y, x, y+1);

				it = pos[x].erase(it);
			}
		}
		if(rep) q.push(f(u)), d[f(u)]++;
	}

	for(int i = 1; i <= n; i++) {
		printf("%s\n", s[i] + 1);
	}

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int p[N * N];
int Lx[N * N], Ly[N * N], Rx[N * N], Ry[N * N];;
int f(int x) {
	return x == p[x] ? x : p[x] = f(p[x]);
}

void join(int i, int j, int ii, int jj) {
	int u = f(ii * N + jj);
	int v = f(i * N + j);
	if(u == v) return;
	p[v] = u;
	Lx[u] = min(Lx[u], Lx[v]);
	Ly[u] = min(Ly[u], Ly[v]);
	Rx[u] = max(Rx[u], Rx[v]);
	Ry[u] = max(Ry[u], Ry[v]);
}

int n, m;
char s[N][N];
int mat[N][N];

int main() {

	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf(" %s", s[i] + 1);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			p[i * N + j] = i * N + j;
			Lx[i * N + j] = Rx[i * N + j] = i;
			Ly[i * N + j] = Ry[i * N + j] = j;
			if(s[i][j] == '*') continue;
			if(s[i - 1][j] == '.') join(i, j, i-1, j);
			if(s[i][j - 1] == '.') join(i, j, i, j-1);
		}
	}

	while(1) {
		memset(mat, 0, sizeof mat);
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
			if(s[i][j] == '*') continue;
			int u = i * N + j;
			if(f(u) != u) continue;
			mat[ Lx[u] ][ Ly[u] ]++;
			mat[ Rx[u]+1 ][ Ly[u] ]--;
			mat[ Lx[u] ][ Ry[u]+1 ]--;
			mat[ Rx[u]+1 ][ Ry[u]+1 ]++;
		}
		bool rep = false;
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
			mat[i][j] += mat[i][j-1] + mat[i-1][j] - mat[i-1][j-1];
			if(mat[i][j] and s[i][j] == '*') {
				s[i][j] = '.';
				rep = true;
				if(s[i - 1][j] == '.') join(i, j, i-1, j);
				if(s[i][j - 1] == '.') join(i, j, i, j-1);
			}
		}
		if(!rep) break;
	}

	for(int i = 1; i <= n; i++) {
		printf("%s\n", s[i] + 1);
	}

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int p[N * N];
int Lx[N * N], Ly[N * N], Rx[N * N], Ry[N * N];;
int f(int x) {
	return x == p[x] ? x : p[x] = f(p[x]);
}

void join(int i, int j, int ii, int jj) {
	int u = f(ii * N + jj);
	int v = f(i * N + j);
	if(u == v) return;
	p[v] = u;
	Lx[u] = min(Lx[u], Lx[v]);
	Ly[u] = min(Ly[u], Ly[v]);
	Rx[u] = max(Rx[u], Rx[v]);
	Ry[u] = max(Ry[u], Ry[v]);
}

int n, m;
char s[N][N];
int mat[N][N];

set<int> pos[N];

int main() {

	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf(" %s", s[i] + 1);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			p[i * N + j] = i * N + j;
			Lx[i * N + j] = Rx[i * N + j] = i;
			Ly[i * N + j] = Ry[i * N + j] = j;
			if(s[i][j] == '*') continue;
			if(s[i - 1][j] == '.') join(i, j, i-1, j);
			if(s[i][j - 1] == '.') join(i, j, i, j-1);
		}
	}

	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
		if(s[i][j] == '*') {
			pos[i].insert(j);
		}
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
		if(s[i][j] == '*') continue;
		int u = i * N + j;
		if(f(u) == u) q.push(u);
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		int i = u / N, j = u % N;
		bool rep = false;
		for(int x = Lx[u]; x <= Rx[u]; x++) {
			auto it = pos[x].lower_bound(Ly[u]);
			while(it != pos[x].end() and *it <= Ry[u]) {
				int y = *it;
				s[x][y] = '.';
				rep = true;
				if(s[x - 1][y] == '.') join(x, y, x-1, y);
				if(s[x][y - 1] == '.') join(x, y, x, y-1);
				if(s[x + 1][y] == '.') join(x, y, x+1, y);
				if(s[x][y + 1] == '.') join(x, y, x, y+1);

				it = pos[x].erase(it);
			}
		}
		if(rep) q.push(u);
	}

	for(int i = 1; i <= n; i++) {
		printf("%s\n", s[i] + 1);
	}

}


#include <stdio.h>
#include <iostream>
const int N=2050;
char ch[N][N];
void work(int x, int y)
{
	int i,j,cnt=0;
	for(i=0;i<2;i++) for(j=0;j<2;j++) cnt+=ch[x+i][y+j]=='.';
	if(cnt==3)
	{
		for(i=0;i<2;i++) for(j=0;j<2;j++) ch[x+i][y+j]='.';
		for(i=-1;i<2;i++) for(j=-1;j<2;j++) work(x+i,y+j);
	}
}
int main()
{
	int n,m,i,j, idx, jdx;
	scanf("%i %i",&n,&m);
	char nm[2000][2000];
	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cin >> nm[idx][jdx];
		}
	}

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			ch[idx][jdx] = nm[idx][jdx];
		}
	}

	for(i=1;i<n;i++) for(j=1;j<m;j++) work(i,j);

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cout << ch[idx][jdx];
		}
		cout << endl;
	}
}


#include <stdio.h>
#include <iostream>
using namespace std;
const int N=2050;
char ch[N][N];
void work(int x, int y)
{
	int i,j,cnt=0;
	for(i=0;i<2;i++) for(j=0;j<2;j++) cnt+=ch[x+i][y+j]=='.';
	if(cnt==3)
	{
		for(i=0;i<2;i++) for(j=0;j<2;j++) ch[x+i][y+j]='.';
		for(i=-1;i<2;i++) for(j=-1;j<2;j++) work(x+i,y+j);
	}
}
int main()
{
	int n,m,i,j, idx, jdx;
	scanf("%i %i",&n,&m);
	char nm[2000][2000];
	for (idx=1; idx<=n; ++idx){
		for (jdx = 1; jdx<=m; ++jdx){
			cin >> nm[idx][jdx];
		}
	}

	for (idx=1; idx<=n; ++idx){
		for (jdx = 1; jdx<=m; ++jdx){
			ch[idx][jdx] = nm[idx][jdx];
		}
	}

	for(i=1;i<n;i++) for(j=1;j<m;j++) work(i,j);

	for (idx=1; idx<=n; ++idx){
		for (jdx = 1; jdx<=m; ++jdx){
			cout << ch[idx][jdx];
		}
		cout << endl;
	}
}


#include <stdio.h>
const int N=2050;
char ch[N][N];
void work(int x, int y)
{
	int i,j,cnt=0;
	for(i=0;i<2;i++) for(j=0;j<2;j++) cnt+=ch[x+i][y+j]=='.';
	if(cnt==3)
	{
		for(i=0;i<2;i++) for(j=0;j<2;j++) ch[x+i][y+j]='.';
		for(i=-1;i<2;i++) for(j=-1;j<2;j++) work(x+i,y+j);
	}
}
int main()
{
	int n,m,i,j, idx, jdx;
	scanf("%i %i",&n,&m);
	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cin >> nm[idx][jdx];
		}
	}

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			ch[idx][jdx] = nm[idx][jdx];
		}
	}

	for(i=1;i<n;i++) for(j=1;j<m;j++) work(i,j);

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cout << ch[idx][jdx];
		}
		cout << endl;
	}
}


#include <stdio.h>
#include <iostream>
using namespace std;
char nm[2005][2005];
void work(int x, int y)
{
	int i,j,cnt=0;
	for(i=0;i<2;i++) for(j=0;j<2;j++) cnt+=nm[x+i][y+j]=='.';
	if(cnt==3)
	{
		for(i=0;i<2;i++) for(j=0;j<2;j++) nm[x+i][y+j]='.';
		for(i=-1;i<2;i++) for(j=-1;j<2;j++) work(x+i,y+j);
	}
}
int main()
{
	int n,m,i,j, idx, jdx;
	scanf("%i %i",&n,&m);

	for (idx=1; idx<=n; ++idx){
		for (jdx = 1; jdx<=m; ++jdx){
			cin >> nm[idx][jdx];
		}
	}

	for(i=1;i<n;i++) for(j=1;j<m;j++) work(i,j);

	for (idx=1; idx<=n; ++idx){
		for (jdx = 1; jdx<=m; ++jdx){
			cout << nm[idx][jdx];
		}
		cout << endl;
	}
}


#include <stdio.h>
const int N=2050;
char ch[N][N];
void work(int x, int y)
{
	int i,j,cnt=0;
	for(i=0;i<2;i++) for(j=0;j<2;j++) cnt+=ch[x+i][y+j]=='.';
	if(cnt==3)
	{
		for(i=0;i<2;i++) for(j=0;j<2;j++) ch[x+i][y+j]='.';
		for(i=-1;i<2;i++) for(j=-1;j<2;j++) work(x+i,y+j);
	}
}
int main()
{
	int n,m,i,j, idx, jdx;
	scanf("%i %i",&n,&m);
	char nm[2000][2000];
	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cin >> nm[idx][jdx];
		}
	}

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			ch[idx][jdx] = nm[idx][jdx];
		}
	}

	for(i=1;i<n;i++) for(j=1;j<m;j++) work(i,j);

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cout << ch[idx][jdx];
		}
		cout << endl;
	}
}


#include <stdio.h>
#include <iostream>
using namespace std;
char nm[2000][2000];
void work(int x, int y)
{
	int i,j,cnt=0;
	for(i=0;i<2;i++) for(j=0;j<2;j++) cnt+=nm[x+i][y+j]=='.';
	if(cnt==3)
	{
		for(i=0;i<2;i++) for(j=0;j<2;j++) nm[x+i][y+j]='.';
		for(i=-1;i<2;i++) for(j=-1;j<2;j++) work(x+i,y+j);
	}
}
int main()
{
	int n,m,i,j, idx, jdx;
	scanf("%i %i",&n,&m);

	for (idx=1; idx<=n; ++idx){
		for (jdx = 1; jdx<=m; ++jdx){
			cin >> nm[idx][jdx];
		}
	}

	for(i=1;i<n;i++) for(j=1;j<m;j++) work(i,j);

	for (idx=1; idx<=n; ++idx){
		for (jdx = 1; jdx<=m; ++jdx){
			cout << nm[idx][jdx];
		}
		cout << endl;
	}
}


#include <stdio.h>
#include <iostream>
using namespace std;
const int N=2050;
char ch[N][N];
void work(int x, int y)
{
	int i,j,cnt=0;
	for(i=0;i<2;i++) for(j=0;j<2;j++) cnt+=ch[x+i][y+j]=='.';
	if(cnt==3)
	{
		for(i=0;i<2;i++) for(j=0;j<2;j++) ch[x+i][y+j]='.';
		for(i=-1;i<2;i++) for(j=-1;j<2;j++) work(x+i,y+j);
	}
}
int main()
{
	int n,m,i,j, idx, jdx;
	scanf("%i %i",&n,&m);
	char nm[2000][2000];
	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cin >> nm[idx][jdx];
		}
	}

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			ch[idx][jdx] = nm[idx][jdx];
		}
	}

	for(i=1;i<n;i++) for(j=1;j<m;j++) work(i,j);

	for (idx=0; idx<n; ++idx){
		for (jdx = 0; jdx<m; ++jdx){
			cout << ch[idx][jdx];
		}
		cout << endl;
	}
}


//<-^->ino
// meet-in-the-middle!
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <iomanip>
#include <queue>
using namespace std;
//No Type
#define pb push_back
#define pp pop_back
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;

const int mod = (int)1e9 + 7;
const int MAXN = 3e5+12;
const int INF = (int)1e9 + 7;
const int NN = 50;

int n,m;

char a[2005][2005];

string s[2005];

void dfs (int x, int y) {
	if (x < 0 || y < 0 || x == n-1 || y == m - 1) {
		return;
	}
	int ans = 0;
	for (int i = 0; i < 2; i ++) {
		for (int j = 0; j < 2; j ++) {
			if (s[x + i][y + j] == '*') {
				ans ++;
			}
		}
	}
	if (ans == 1) {
		for (int i = 0; i < 2; i ++) {
			for (int j = 0; j < 2; j ++) {
				s[x + i][y + j] = '.';
			}
		}
		for (int i = -1; i < 2; i ++) {
			for (int j = -1; j < 2; j ++) {
				dfs (x + i, y + j);
			}
		}
	}

}

int main()
{
	NoType;

	cin >> n >> m;

	for (int i = 0; i < n; i ++) {
		cin >> s[i];
	}

 	for (int i = 0; i < n; i ++) {
 		for (int j = 0; j < s[i].size(); j ++) {
 			dfs (i, j);
 		}
 	}

 	for (int i = 0; i < n; i ++) {
 		for (int j = 0; j < s[i].size(); j ++) {
 			cout << s[i][j];
 		}
 		cout << endl;
 	}

	return 0;
}


// avvinci - summer_17
// #include"prettyprint.hpp"
#include<bits/stdc++.h>
using namespace std;

typedef pair<long long int , long long int> P;

#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fs first
#define sc second
#define ll long long int
#define fr(it,st,en) for(it=st;it<en;it++)
#define all(container) container.begin(),container.end()
#define INP ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ws(x) cout << #x << " = " << x << endl
#define sz(x)  (ll)x.size()
#define N 2004

const long long infl = 1e18+5;

ll n,m,k,q,x,y,mx =-1,mn=infl,f,val,sz,sm,cnt,ans,t=1,i,j,ind=-1;
char a[N][N] ;
int dis[N][N], maxx,minx,miny,maxy;
int xa[] = {0,1,0,-1};
int ya[] = {1,0,-1,0} ;

int fun(int x , int y ){

	dis[x][y] = 1;

	int i ;
	fr(i,0,4){
		int u = x + xa[i];
		int v = y + ya[i] ;

		if(u < 0 || u >= n || v < 0  || v >= m ) continue ;

		if(dis[u][v] != 0 || a[u][v] == '*' ) continue ;

		maxx = max(maxx, u );
		maxy = max(maxy,v );
		minx = min(minx,u);
		miny = min(miny, v) ;
		fun(u,v);
	}

}
void printt(){
	int i , j ;

	fr(i,0,n){
	fr(j,0,m){
		cout<<a[i][j];

	}
	cout<<"\n";
	}
	cout<<"\n";
}
int main(){
INP
if (fopen("inp.txt", "r")) {
    freopen("myfile.txt","w",stdout);
    freopen("inp.txt", "r", stdin);
}

cin>>n>>m;
fr(i,0,n){
	fr(j,0,m){
		cin>>a[i][j];
	}
}

fr(i,0,n){
	fr(j,0,m){

		if(dis[i][j] == 0 && a[i][j] == '.'){
			maxx = i ; minx = i ;
			maxy = j ; miny =  j ;
			fun(i,j) ;
			int u,v ;

			fr(u,minx,maxx+1){
				fr(v,miny,maxy+1){
					if(a[u][v] == '*'){
						dis[u][v] = 1 ;
						a[u][v] = '.';
						ans++;
					}
				}
			}

		}
	}
}

printt();

return 0 ;
}


// avvinci - summer_17
// #include"prettyprint.hpp"
#include<bits/stdc++.h>
using namespace std;

typedef pair<long long int , long long int> P;

#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fs first
#define sc second
#define ll long long int
#define fr(it,st,en) for(it=st;it<en;it++)
#define all(container) container.begin(),container.end()
#define INP ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ws(x) cout << #x << " = " << x << endl
#define sz(x)  (ll)x.size()
#define N 2004

const long long infl = 1e18+5;

ll n,m,k,x,y,mx =-1,mn=infl,f,val,sz,sm,cnt,ans,t=1,i,j,ind=-1;
char a[N][N] ;
queue<P > q ;
int ok(int u , int v ){
	if(u<0 || v< 0 || u>=n || v >= m || a[u][v] =='.')
		return 0 ;
	if(u >0 ){
		if(v > 0)
			if(a[u][v-1] == '.' && a[u-1][v-1] =='.' && a[u-1][v] =='.') return 1 ;
		if(v < m-1)
			if(a[u][v+1] == '.' && a[u-1][v+1] =='.' && a[u-1][v] =='.') return 1 ;

	}
	if(u< n-1){
		if(v > 0 )
			if(a[u][v-1] == '.' && a[u+1][v-1] =='.' && a[u+1][v] =='.') return 1 ;
		if(v < m-1)
			if(a[u][v+1] == '.' && a[u+1][v+1] =='.' && a[u+1][v] =='.') return 1 ;

	}

	return 0 ;
}
int main(){
INP
if (fopen("inp.txt", "r")) {
    freopen("myfile.txt","w",stdout);
    freopen("inp.txt", "r", stdin);
}

cin>>n>>m;
fr(i,0,n){
	fr(j,0,m){
		cin>>a[i][j];
		// if(ok(i,j))
			q.push({i,j});
	}
}

while(!q.empty()){
	int u = q.front().fs;
	int v = q.front().sc ;
	q.pop();
	if(ok(u,v)){
		a[u][v] = '.';
		fr(i,-1,2)
			fr(j,-1,2)
				if(i!=0 || j!=0) q.push({u+i,v+j});

	}
}
fr(i,0,n){
	fr(j,0,m){
		cout<<a[i][j];
	}
	cout<<"\n";
}

return 0 ;
}


#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
#define MN 2002
char grid[MN][MN];
int visited[MN][MN];
int dy[8] = {-1, 0, 1, 0, -1, 1, -1, 1}, dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N, M;

bool isCan(int y, int x) {
    if(y < 1 || y > N || x < 1 || x > M) return false;
    if(grid[y][x] != '.') return false;
    return true;
}

int main () {
    scanf("%d%d", &N, &M);
    for(int i=1;i<=N;i++) scanf("%s", grid[i]+1);

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            if(grid[i][j] == '*') continue;
            if(visited[i][j]) continue;

            queue<int> que;
            que.push(i*M+j);
            visited[i][j] = 1;

            while(!que.empty()) {
                int y = que.front()/M;
                int x = que.front()%M;
                que.pop();

                for(int k=0;k<8;k++) {
                    int ny = y+dy[k];
                    int nx = x+dx[k];

                    if(ny < 1 || ny > N || nx < 1 || nx > M) continue;
                    if(visited[ny][nx]) continue;

                    if(grid[ny][nx] == '.') {
                        if(k<4) {
                            visited[ny][nx] = 1;
                            que.push(ny*M+nx);
                        }
                    } else {
                        for(int p=0;p<4;p++) {
                            int ay = dy[p%4];
                            int ax = dx[p%4];

                            int by = dy[(p+1)%4];
                            int bx = dx[(p+1)%4];

                            int cy = ay+by;
                            int cx = ax+bx;

                            if(!isCan(ny+ay, nx+ax)) continue;
                            if(!isCan(ny+by, nx+bx)) continue;
                            if(!isCan(ny+cy, nx+cx)) continue;
                            if(visited[ny][nx]) continue;

                            visited[ny][nx] = 1;
                            grid[ny][nx] = '.';
                            que.push(ny*M+nx);

                            break;
                        }
                    }
                }
            }
        }
    }

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) printf("%c", grid[i][j]);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
#define MN 2002
char grid[MN][MN];
int visited[MN][MN];
int dy[8] = {-1, 0, 1, 0, -1, 1, -1, 1}, dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N, M;

bool isCan(int y, int x) {
    if(y < 1 || y > N || x < 1 || x > M) return false;
    if(grid[y][x] != '.') return false;
    return true;
}

int main () {
    scanf("%d%d", &N, &M);
    for(int i=1;i<=N;i++) scanf("%s", grid[i]+1);

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            if(grid[i][j] == '*') continue;
            if(visited[i][j]) continue;

            queue<int> que;
            que.push(i*MN+j);
            visited[i][j] = 1;

            while(!que.empty()) {
                int y = que.front()/MN;
                int x = que.front()%MN;
                que.pop();

                for(int k=0;k<8;k++) {
                    int ny = y+dy[k];
                    int nx = x+dx[k];

                    if(ny < 1 || ny > N || nx < 1 || nx > M) continue;
                    if(visited[ny][nx]) continue;

                    if(grid[ny][nx] == '.') {
                        if(k<4) {
                            visited[ny][nx] = 1;
                            que.push(ny*MN+nx);
                        }
                    } else {
                        for(int p=0;p<4;p++) {
                            int ay = dy[p%4];
                            int ax = dx[p%4];

                            int by = dy[(p+1)%4];
                            int bx = dx[(p+1)%4];

                            int cy = ay+by;
                            int cx = ax+bx;

                            if(!isCan(ny+ay, nx+ax)) continue;
                            if(!isCan(ny+by, nx+bx)) continue;
                            if(!isCan(ny+cy, nx+cx)) continue;
                            if(visited[ny][nx]) continue;

                            visited[ny][nx] = 1;
                            grid[ny][nx] = '.';
                            que.push(ny*MN+nx);

                            break;
                        }
                    }
                }
            }
        }
    }

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) printf("%c", grid[i][j]);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
#define MN 2002
char grid[MN][MN];
int visited[MN][MN];
int dy[8] = {-1, 0, 1, 0, -1, 1, -1, 1}, dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N, M;

bool isCan(int y, int x) {
    if(y < 1 || y > N || x < 1 || x > M) return false;
    if(grid[y][x] != '.') return false;
    return true;
}

int main () {
    scanf("%d%d", &N, &M);
    for(int i=1;i<=N;i++) scanf("%s", grid[i]+1);

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            if(grid[i][j] == '*') continue;
            if(visited[i][j]) continue;

            queue<int> que;
            que.push(i*MN+j);
            visited[i][j] = 1;

            while(!que.empty()) {
                int y = que.front()/MN;
                int x = que.front()%MN;
                que.pop();

                for(int k=0;k<8;k++) {
                    int ny = y+dy[k];
                    int nx = x+dx[k];

                    if(ny < 1 || ny > N || nx < 1 || nx > M) continue;
                    if(visited[ny][nx]) continue;

                    if(grid[ny][nx] == '.') {
                        if(k<4) {
                            visited[ny][nx] = 1;
                            que.push(ny*MN+nx);
                        }
                    } else {
                        for(int p=0;p<4;p++) {
                            int ay = dy[p%4];
                            int ax = dx[p%4];

                            int by = dy[(p+1)%4];
                            int bx = dx[(p+1)%4];

                            int cy = ay+by;
                            int cx = ax+bx;

                            if(ny+ay < 1 || ny+ay > N || nx+ax < 1 || nx+ax > M) continue;
                            if(grid[ny+ay][nx+ax] != '.') continue;

                            if(ny+by < 1 || ny+by > N || nx+bx < 1 || nx+bx > M) continue;
                            if(grid[ny+by][nx+bx] != '.') continue;

                            if(ny+cy < 1 || ny+cy > N || nx+cx < 1 || nx+cx > M) continue;
                            if(grid[ny+cy][nx+cx] != '.') continue;

                            if(visited[ny][nx]) continue;

                            visited[ny][nx] = 1;
                            grid[ny][nx] = '.';
                            que.push(ny*MN+nx);

                            break;
                        }
                    }
                }
            }
        }
    }

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) printf("%c", grid[i][j]);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
#define MN 2002
char grid[MN][MN];
int visited[MN][MN];
int dy[8] = {-1, 0, 1, 0, -1, 1, -1, 1}, dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N, M;

bool isCan(int y, int x) {
    if(y < 1 || y > N || x < 1 || x > M) return false;
    if(grid[y][x] != '.') return false;
    return true;
}

int main () {
    scanf("%d%d", &N, &M);
    for(int i=1;i<=N;i++) scanf("%s", grid[i]+1);

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            if(grid[i][j] == '*') continue;
            if(visited[i][j]) continue;

            queue<int> que;
            que.push(i*M+j);
            visited[i][j] = 1;

            while(!que.empty()) {
                int y = que.front()/MN;
                int x = que.front()%MN;
                que.pop();

                for(int k=0;k<8;k++) {
                    int ny = y+dy[k];
                    int nx = x+dx[k];

                    if(ny < 1 || ny > N || nx < 1 || nx > M) continue;
                    if(visited[ny][nx]) continue;

                    if(grid[ny][nx] == '.') {
                        if(k<4) {
                            visited[ny][nx] = 1;
                            que.push(ny*MN+nx);
                        }
                    } else {
                        for(int p=0;p<4;p++) {
                            int ay = dy[p%4];
                            int ax = dx[p%4];

                            int by = dy[(p+1)%4];
                            int bx = dx[(p+1)%4];

                            int cy = ay+by;
                            int cx = ax+bx;

                            if(!isCan(ny+ay, nx+ax)) continue;
                            if(!isCan(ny+by, nx+bx)) continue;
                            if(!isCan(ny+cy, nx+cx)) continue;
                            if(visited[ny][nx]) continue;

                            visited[ny][nx] = 1;
                            grid[ny][nx] = '.';
                            que.push(ny*MN+nx);

                            break;
                        }
                    }
                }
            }
        }
    }

    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) printf("%c", grid[i][j]);
        printf("\n");
    }
    return 0;
}