Problem: There are n military men in the Berland army. Some of them have given orders to other military men by now. Given m pairs (xi, yi), meaning that the military man xi gave the i-th order to another military man yi.

It is time for reform! The Berland Ministry of Defence plans to introduce ranks in the Berland army. Each military man should be assigned a rank — integer number between 1 and k, inclusive. Some of them have been already assigned a rank, but the rest of them should get a rank soon.

Help the ministry to assign ranks to the rest of the army so that:

  * for each of m orders it is true that the rank of a person giving the order (military man xi) is strictly greater than the rank of a person receiving the order (military man yi); 
  * for each rank from 1 to k there is at least one military man with this rank. 

Input

The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 0 ≤ m ≤ 2·105, 1 ≤ k ≤ 2·105) — number of military men in the Berland army, number of orders and number of ranks.

The second line contains n integers r1, r2, ..., rn, where ri > 0 (in this case 1 ≤ ri ≤ k) means that the i-th military man has been already assigned the rank ri; ri = 0 means the i-th military man doesn't have a rank yet.

The following m lines contain orders one per line. Each order is described with a line containing two integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi). This line means that the i-th order was given by the military man xi to the military man yi. For each pair (x, y) of military men there could be several orders from x to y.

Output

Print n integers, where the i-th number is the rank of the i-th military man. If there are many solutions, print any of them.

If there is no solution, print the only number -1.

Examples

Input

5 3 3
0 3 0 0 2
2 4
3 4
3 5


Output

1 3 3 2 2 


Input

7 6 5
0 4 5 4 1 0 0
6 1
3 6
3 1
7 5
7 1
7 4


Output

2 4 5 4 1 3 5 


Input

2 2 2
2 1
1 2
2 1


Output

-1

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {

        public class MilitaryMan {
            int Count;
            int Rank;
            int MaximalRank;
            int MinimalRank = 0;
            boolean IsVisited = false;
            boolean WasVisited = false;

            HashSet<MilitaryMan> GivenOrderTo = new HashSet<>();
            HashSet<MilitaryMan> GivenOrderBy = new HashSet<>();

            public MilitaryMan(int Rank, int MaximalRank) {
                this.Rank = Rank;
                this.MaximalRank = MaximalRank;
                if (this.Rank != -1) {
                    this.MinimalRank = this.Rank;
                    this.MaximalRank = this.Rank;
                }
            }

            public void UpdateCount() {
                Count = GivenOrderTo.size();
            }

            public boolean IsThereALoop() {
                if (IsVisited) return true;
                if (WasVisited) return false;

                IsVisited = true;
                for (MilitaryMan m : GivenOrderBy) {
                    if (m.IsThereALoop()) return true;
                }

                IsVisited = false;
                WasVisited = true;
                return false;
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.NextInt();
            int m = in.NextInt();
            int k = in.NextInt();
            if (n < k) {
                out.println("-1");
                return;
            }
            boolean[] availableRanks = new boolean[k];
            Arrays.fill(availableRanks, true);
            MilitaryMan[] s = new MilitaryMan[n];

            for (int i = 0; i < n; i++) {
                s[i] = new MilitaryMan(in.NextInt() - 1, k - 1);
                if (s[i].Rank != -1) availableRanks[s[i].Rank] = false;
            }

            for (int i = 0; i < m; i++) {
                int u = in.NextInt() - 1;
                int v = in.NextInt() - 1;
                s[u].GivenOrderTo.add(s[v]);
                s[v].GivenOrderBy.add(s[u]);
            }

            for (MilitaryMan militaryMan : s) {
                if (militaryMan.IsThereALoop()) {
                    out.println("-1");
                    return;
                }
            }

            Queue<MilitaryMan> qMin = new PriorityQueue<>(Comparator.comparingInt(o -> o.MinimalRank));
            Queue<MilitaryMan> qMax = new PriorityQueue<>(Comparator.comparingInt(o -> -1 * o.MaximalRank));

            for (MilitaryMan militaryMan : s) {
                if (militaryMan.GivenOrderTo.isEmpty() || militaryMan.Rank != -1) {
                    qMin.add(militaryMan);
                }
                if (militaryMan.GivenOrderBy.isEmpty() || militaryMan.Rank != -1) {
                    qMax.add(militaryMan);
                }
            }
            while (!qMin.isEmpty()) {
                MilitaryMan militaryMan = qMin.poll();
                for (MilitaryMan militaryMan1 : militaryMan.GivenOrderBy) {
                    if (militaryMan1.MinimalRank < militaryMan.MinimalRank + 1) {
                        militaryMan1.MinimalRank = militaryMan.MinimalRank + 1;
                        qMin.add(militaryMan1);
                    }
                }
            }

            while (!qMax.isEmpty()) {
                MilitaryMan militaryMan = qMax.poll();
                for (MilitaryMan militaryMan1 : militaryMan.GivenOrderTo) {
                    if (militaryMan1.MaximalRank > militaryMan.MaximalRank - 1) {
                        militaryMan1.MaximalRank = militaryMan.MaximalRank - 1;
                        qMax.add(militaryMan1);
                    }
                }
            }

            for (MilitaryMan militaryMan : s) {
                if (militaryMan.MinimalRank > militaryMan.MaximalRank) {
                    out.println("-1");
                    return;
                }
            }

            qMax = new PriorityQueue<>(Comparator.comparingInt(o -> o.MaximalRank));

            for (MilitaryMan militaryMan : s) militaryMan.UpdateCount();

            for (MilitaryMan militaryMan : s) {
                if (militaryMan.GivenOrderTo.isEmpty())
                    qMin.add(militaryMan);
            }
            int currentRank = 0;
            while (!qMax.isEmpty() || !qMin.isEmpty()) {
                while (!qMin.isEmpty() && qMin.peek().MinimalRank <= currentRank) {
                    qMax.add(qMin.poll());
                }
                while (!qMax.isEmpty() && qMax.peek().MaximalRank <= currentRank) {
                    MilitaryMan militaryMan = qMax.poll();
                    militaryMan.Rank = currentRank;
                    availableRanks[currentRank] = false;
                    for (MilitaryMan militaryMan1 : militaryMan.GivenOrderBy) {
                        militaryMan1.Count--;
                        if (militaryMan1.Count == 0) {
                            qMin.add(militaryMan1);
                        }
                    }
                }
                if (availableRanks[currentRank]) {
                    if (qMax.isEmpty()) {
                        out.println("-1");
                        return;
                    }
                    MilitaryMan militaryMan = qMax.poll();
                    militaryMan.Rank = currentRank;
                    availableRanks[currentRank] = false;
                    for (MilitaryMan militaryMan1 : militaryMan.GivenOrderBy) {
                        militaryMan1.Count--;
                        if (militaryMan1.Count == 0) {
                            qMin.add(militaryMan1);
                        }
                    }
                }
                currentRank++;
            }
            if (currentRank != k) {
                out.println(-1);
                return;
            }
            for (int i = 0; i < n; i++) {
                out.print((s[i].Rank + 1) + " ");
            }
            out.println();
        }
    }

    public static int GetMax(int[] ar) {
        int max = Integer.MIN_VALUE;
        for (int a : ar) {
            max = Math.max(max, a);
        }
        return max;
    }

    public static int[] GetCount(int[] ar) {
        return GetCount(ar, GetMax(ar));
    }

    public static int[] GetCount(int[] ar, int maxValue) {
        int[] dp = new int[maxValue + 1];
        for (int a : ar) {
            dp[a]++;
        }
        return dp;
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String Next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(Next());
        }

        public long NextLong() {
            return Long.parseLong(Next());
        }

        public double NextDouble() {
            return Double.parseDouble(Next());
        }

        public int[] NextIntArray(int n) {
            return NextIntArray(n, 0);
        }

        public int[] NextIntArray(int n, int offset) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = NextInt() - offset;
            }
            return a;
        }

        public int[][] NextIntMatrix(int n, int m) {
            return NextIntMatrix(n, m, 0);
        }

        public int[][] NextIntMatrix(int n, int m, int offset) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = NextInt() - offset;
                }
            }
            return a;
        }
    }
}


//import java.io.OutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.PrintWriter;
//import java.util.*;
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//
//public class Main {
//    public static void main(String[] args) {
//        InputStream inputStream = System.in;
//        OutputStream outputStream = System.out;
//        InputReader in = new InputReader(inputStream);
//        PrintWriter out = new PrintWriter(outputStream);
//        TaskC solver = new TaskC();
//        solver.solve(1, in, out);
//        out.close();
//    }
//
//    static class TaskC {
//
//        public class UndirectedEdge {
//            Node u, v;
//            int direction = 0;
//            boolean ub = false, vb = false;
//
//            public UndirectedEdge(Node u, Node v) {
//                this.u = u;
//                this.v = v;
//            }
//
//        }
//
//        public class Node {
//            boolean visited = false;
//            HashSet<Node> e = new HashSet<>();
//            HashSet<Node> e_ = new HashSet<>();
//            ArrayList<UndirectedEdge> eu = new ArrayList<>();
//
//        }
//
//        public void solve(int testNumber, InputReader in, PrintWriter out) {
//            int n = in.NextInt();
//            int m = in.NextInt();
//            int s = in.NextInt() - 1;
//            Node[] nodes = new Node[s];
//            for (int i = 0; i < n; i++) nodes[i] = new Node();
//            for (; m > 0; m--) {
//                int t = in.NextInt();
//                int u = in.NextInt() - 1;
//                int v = in.NextInt() - 1;
//                if (t == 1) {
//                    nodes[u].e.add(nodes[v]);
//                    nodes[v].e_.add(nodes[u]);
//                } else {
//                    UndirectedEdge e = new UndirectedEdge(nodes[u], nodes[v]);
//                    nodes[u].eu.add(e);
//                    nodes[v].eu.add(e);
//                }
//            }
//            Queue<UndirectedEdge> q = new LinkedList<>();
//            Queue<Node> qn = new LinkedList<>();
//            qn.add(nodes[s]);
//            do {
//                while (q.isEmpty() == false) {
//                    UndirectedEdge e = q.poll();
//                    if (e.ub) e.direction = 0;
//                    else e.direction = 1;
//                    qn.add(e.v);
//                    qn.add(e.u);
//                }
//                while (qn.isEmpty() == false) {
//                    Node nn = qn.poll();
//                    if (nn.visited) continue;
//                    nn.visited = true;
//                    qn.addAll(nn.e);
//                    for (UndirectedEdge ue : nn.eu) {
//                        ue.vb |= ue.v == nn;
//                        ue.ub |= ue.u == nn;
//                    }
//                }
//            } while (q.isEmpty() == false);
//            for ()
//        }
//    }
//
//    public static int GetMax(int[] ar) {
//        int max = Integer.MIN_VALUE;
//        for (int a : ar) {
//            max = Math.max(max, a);
//        }
//        return max;
//    }
//
//    public static int GetMin(int[] ar) {
//        int min = Integer.MAX_VALUE;
//        for (int a : ar) {
//            min = Math.min(min, a);
//        }
//        return min;
//    }
//
//    public static int[] GetCount(int[] ar) {
//        return GetCount(ar, GetMax(ar));
//    }
//
//    public static int[] GetCount(int[] ar, int maxValue) {
//        int[] dp = new int[maxValue + 1];
//        for (int a : ar) {
//            dp[a]++;
//        }
//        return dp;
//    }
//
//    static class InputReader {
//        public BufferedReader reader;
//        public StringTokenizer tokenizer;
//
//        public InputReader(InputStream stream) {
//            reader = new BufferedReader(new InputStreamReader(stream), 32768);
//            tokenizer = null;
//        }
//
//        public String Next() {
//            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
//                try {
//                    tokenizer = new StringTokenizer(reader.readLine());
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//            }
//            return tokenizer.nextToken();
//        }
//
//        public int NextInt() {
//            return Integer.parseInt(Next());
//        }
//
//        public long NextLong() {
//            return Long.parseLong(Next());
//        }
//
//        public double NextDouble() {
//            return Double.parseDouble(Next());
//        }
//
//        public int[] NextIntArray(int n) {
//            return NextIntArray(n, 0);
//        }
//
//        public int[] NextIntArray(int n, int offset) {
//            int[] a = new int[n];
//            for (int i = 0; i < n; i++) {
//                a[i] = NextInt() - offset;
//            }
//            return a;
//        }
//
//        public int[][] NextIntMatrix(int n, int m) {
//            return NextIntMatrix(n, m, 0);
//        }
//
//        public int[][] NextIntMatrix(int n, int m, int offset) {
//            int[][] a = new int[n][m];
//            for (int i = 0; i < n; i++) {
//                for (int j = 0; j < m; j++) {
//                    a[i][j] = NextInt() - offset;
//                }
//            }
//            return a;
//        }
//    }
//}