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5 1
2 2
2 3
 83 8
54 3 52 12 61 36 65 62 69 49 47 77 31 15 21 14 73 29 6 26 37 17 81 75 43 30 58 76 16 8 11 5 27 35 7 66 50 67 2 39 45 28 60 71 38 82 53 1 42 13 44 72 22 4 9 25 19 57 10 70 18 68 32 34 20 80 23 79 24 63 64 51 59 41 74 48 40 33 46 83 55 56 78
48 80
1 8
71 54
15 59
72 46
36 9
64 29
55 58
 1 1
1
1 1
 5 20
3 4 1 5 2
2 4
3 1
2 2
4 5
4 5
5 2
1 1
2 4
3 3
4 2
3 1
1 1
5 2
1 3
3 1
4 2
1 3
3 3
4 2
4 2
 6 20
4 6 1 3 2 5
2 2
6 5
3 4
3 4
5 6
3 3
5 5
6 6
4 3
2 2
2 2
5 2
3 4
1 4
5 2
4 3
2 5
1 4
3 1
4 3
 2 10
1 2
1 1
2 2
2 2
1 1
1 1
2 2
2 2
1 1
2 2
1 1
 5 3
5 2 3 4 1
2 4
1 4
3 4
 4 1
4 3 1 2
3 4
 3 1
1 3 2
1 2
 2 10
2 1
2 1
1 2
1 1
2 1
1 1
2 1
1 1
1 1
2 1
2 1
 3 1
2 3 1
1 1
 8 1
3 4 1 2 7 8 5 6
3 4
 3 10
1 2 3
2 2
1 1
2 2
3 3
1 1
3 3
3 3
3 3
2 2
1 1

3 2 1 
 6 2 5 7 3 1 4 
 4 2 3 1 
 9 8 6 7 5 3 4 2 1 
 7 6 5 4 3 2 1 
 3 2 1 
 8 4 7 2 6 5 3 1 
 2 3 1 
 4 12 7 1 16 19 3 10 14 8 13 2 11 9 20 5 18 17 6 15 
 6 8 9 4 5 1 7 2 3 
 5 4 3 2 1 
 3 4 1 2 
 5 3 2 4 1 6 
 62 3 52 12 61 36 65 54 69 49 47 77 31 15 21 14 73 29 6 26 37 17 81 75 43 30 58 76 34 8 11 5 27 35 7 66 50 67 2 39 45 28 60 71 38 82 53 83 42 13 44 72 22 64 57 25 19 9 10 70 18 68 32 16 20 80 23 79 24 63 4 51 59 41 74 48 40 33 46 1 55 56 78 
 1 
 3 5 1 4 2 
 4 6 3 1 5 2 
 1 2 
 5 4 3 2 1 
 4 3 2 1 
 3 1 2 
 2 1 
 2 3 1 
 3 4 2 1 7 8 5 6 
 1 2 3 


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

/**
 *
 * @author Rishabh
 */
public class Main {static class Reader {

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

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') {
                    break;
                }
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg) {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) {
                return -ret;
            }
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg) {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) {
                return -ret;
            }
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg) {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }
            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

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

        public void close() throws IOException {
            if (din == null) {
                return;
            }
            din.close();
        }
    }
    public static void main(String[] args) throws IOException {
        Reader r=new Reader();
        int n=r.nextInt();
        int m=r.nextInt();
        int ar[]=new int[n+1];
        for(int i=1;i<=n;i++)ar[i]=r.nextInt();
        
        ArrayList<Integer> gr[]=new ArrayList[n+1];
        for(int i=0;i<=n;i++)gr[i]=new ArrayList<>();
        for(int i=0;i<m;i++){
        int x=r.nextInt();int y=r.nextInt();
        gr[x].add(y);
        gr[y].add(x);
        }
        StringBuilder sb=new StringBuilder();
        for(int i=1;i<=n;i++){
        int max=-1,id=i;
            Queue<Integer> q=new LinkedList<>();
            q.add(i);
            int visited[]=new int[n+1];
            while(!q.isEmpty()){
            int temp=q.remove();
            if(visited[temp]==1)continue;
            visited[temp]=1;
            if(ar[temp]>max && temp>=i){max=ar[temp];id=temp;}
            for(int mm:gr[temp]){
            if(visited[mm]==0 && mm>i)q.add(mm);
            }
            
            }
        
        int temp=ar[i];
        ar[i]=ar[id];
        ar[id]=temp;
sb.append(ar[i]+" ");        
        // System.out.println(Arrays.toString(ar));
        }

System.out.println(sb);
    }
   
}
