import java.io.*;
import java.util.*;
public class G{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
        class MinCostMaxFlow{
                ArrayList<Edge> al[];
                Edge ja[][];
                int d[]; // shortest distances
                int N , S , T , maxFlow ; int minCost;
                final int gmax = Integer.MAX_VALUE / 100;

                int edges = 0;

                class Edge{
                    int u , flow, rid, cost;
                    Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}
                }

                void addEdge(int u , int v , int flow , int cost){
                    int lu = al[u].size(), lv = al[v].size();
                    al[u].add(new Edge(v, flow, cost, lv));
                    al[v].add(new Edge(u, 0, -cost, lu));
                }

                void convertToArray(){
                    ja = new Edge[N][];
                    for(int i = 0; i < N; i++){
                        int sz = al[i].size();
                        ja[i] = new Edge[sz];
                        for(int j = 0; j < sz; j++){
                            ja[i][j] = al[i].get(j);
                        }
                        al[i].clear();
                    }
                }

                MinCostMaxFlow(int n , int source , int sink){
                    N = n; S = source; T = sink; maxFlow = 0; minCost = 0;
                    al = new ArrayList[N];
                    d = new int[N];
                    for(int i = 0; i < N; i++){
                        al[i] = new ArrayList<>();
                    }
                }

                boolean BellmanFord(boolean check){
                    d[0] = 0;
                    for(int i = 0; i < N - 1; i++){
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(e.flow == 0)continue; // not to consider reverse edges
                                d[e.u] = Math.min(d[e.u] , d[j] + e.cost);
                            }
                        }
                    }
                    if(check){// check for negative cycles
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(e.flow == 0)continue;
                                if(d[j] + e.cost < d[e.u]) return false;
                            }
                        }
                    }return true;
                }

                int node[]; // present node

                int visit[]; // 0 -> not added 1 -> not removed 2 -> removed
                int prv[], prve[]; // previous node for augmentation
                int dist[]; // min dist

                boolean simple(){
                    node = new int[N];
                    visit = new int[N];
                    prv = new int[N];
                    prve = new int[N];
                    dist = new int[N];   Arrays.fill(dist , gmax);

                    node[0] = S; dist[0] = 0;
                    int front = 1, back = 0;
                    while(front != back){
                        int u = node[back++]; int distu = dist[u];
                        if(back == N)back = 0;
                        visit[u] = 2;
                        for(int i = 0; i < ja[u].length; i++){
                            Edge e = ja[u][i];
                            if(e.flow == 0)continue;
                            int cdist = distu + e.cost; // no need of reduced cost
                            if(cdist < dist[e.u]){
                                if(visit[e.u] == 0){
                                    node[front] = e.u;
                                    if(++front == N)front = 0;
                                }else if(visit[e.u] == 2){
                                    if(--back == -1)back += N;
                                    node[back] = e.u;
                                }
                                visit[e.u] = 1;
                                prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;
                            }
                        }
                    }
                    return visit[T] != 0;
                }

                class pair{
                    int F; int S;
                    pair(int a, int b){F = a; S = b;}
                }

                boolean dijkstra(){
                    visit = new int[N];
                    prv = new int[N];
                    prve = new int[N];
                    dist = new int[N]; Arrays.fill(dist, gmax);
                    PriorityQueue<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));

                    pq.add(new pair(S , 0)); dist[0] = 0;
                    o : while(!pq.isEmpty()){
                        pair p = pq.poll();
                        while(dist[p.F] < p.S){
                            if(pq.isEmpty()) break o; // had a better val
                            p = pq.poll();
                        }
                        visit[p.F] = 2;
                        for(int i = 0; i < ja[p.F].length; i++){
                            Edge e = ja[p.F][i];
                            if(e.flow == 0)continue; // important
                            int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost
                            if(cdist < dist[e.u]){
                                if(visit[e.u] == 2) return false;
                                pq.add(new pair(e.u , cdist));
                                dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;
                                visit[e.u] = 1;
                            }
                        }
                    }
                    return visit[T] != 0;
                }

                int augment(){
                    int p = T; int min = gmax;
                    while(p != 0){
                        int pp = prv[p], pe = prve[p];
                        int val = ja[pp][pe].flow;
                        min = Math.min(min , val);
                        p = pp;
                    }
                    p = T;
                    while(p != 0){
                        int pp = prv[p], pe = prve[p];
                        ja[pp][pe].flow -= min;
                        ja[p][ja[pp][pe].rid].flow += min;
                        p = pp;
                    }
                    maxFlow += min;
                    return min;
                }

                // if(dist[T] >= 0)return true; // non contributing flow
                boolean calSimple(){
                    // uncomment to check for negative cycles
                    /* boolean possible = BellmanFord(true);
                     if(!possible) return false; */
                    while(simple()){
                        /*if(dist[T] >= 0)return true;*/
                        minCost += dist[T] * augment();
                    }
                    return true;
                }

                void updPotential(){
                    for(int i = 0; i < N; i++){
                        if(visit[i] != 0){
                            d[i] += dist[i] - dist[S];
                        }
                    }
                }
                boolean calWithPotential(){
                    // set true to check for negative cycles
                    // boolean possible = BellmanFord(false);
                    // if(!possible) return false;
                    while(dijkstra()){
                        int min = dist[T] + d[T] - d[S]; // getting back the original cost
                        /*if(dist[T] >= 0)return true;*/
                        minCost += min * augment();
                        updPotential();
                    }
                    return true;
                }
            }
            int n , m, k, c, d, a[], f[];
           public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();
            // S + n
            int maxl = 2 * n, T = n * maxl + 1;
            MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);
            a = new int[k + 1]; f = new int[n + 1];
            for(int i = 1; i <= k; i++){
                a[i] = in.nextInt();
                f[a[i]]++;
            }
            for(int i = 1; i <= n; i++){
                if(f[i] == 0)continue;
                ans.addEdge(0 , i , f[i], 0);
            }
            for(int i = 2; i <= n; i++){
                for(int l = 0; l < maxl - 1; l++){
                    ans.addEdge(l * n + i , (l + 1) * n + i, k, c);
                }
            }
            for(int i = 1; i <= m; i++){
                int a = in.nextInt(), b = in.nextInt();
                for(int l = 0; l < maxl - 1; l++){
                    for(int p = 1; p <= k; p++){
                        if(a != 1)
                            ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);
                        if(b != 1)
                            ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);
                    }
                }
            }
            for(int l = 1; l < maxl; l++){
                ans.addEdge(l * n + 1, T, 1, 0);
            }
            ans.convertToArray();
            ans.calWithPotential();
            // ans.calSimple();
            if(ans.maxFlow != k){
                out.println("BUG");
            }else{
                out.println((int)ans.minCost);
            }
          }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.util.*;
import java.io.*;

public class GG {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int K = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();
        MinCostMaxFlowSolver solver = new EdmondsKarp();
        int[] people = new int[K];
        for(int i = 0; i < K; i++) people[i] = scanner.nextInt()-1;
        Node src = solver.addNode();
        Node snk = solver.addNode();
        int amt = 375;
        Node[][] timeNodes = new Node[N][amt];
        for(int i = 0; i < N; i++) {
            for(int j = 1; j < amt; j++) {
                timeNodes[i][j] = solver.addNode();
                if (j > 1) solver.link(timeNodes[i][j-1], timeNodes[i][j], Integer.MAX_VALUE, 0);
            }
        }
        for(int i = 0; i < K; i++) {
            solver.link(src, timeNodes[people[i]][1], 1, 0);
        }
        for(int i = 1; i < amt; i++) {
            for(int j = 0; j < K; j++) {
                solver.link(timeNodes[0][i], snk, 1, C*i-C);
            }
        }
        for(int i =0; i < M; i++) {
            int a = scanner.nextInt()-1;
            int b = scanner.nextInt()-1;
            for(int j = 1; j < amt-1; j++) {
                for(int k = 1; k <= K; k++) {
                    solver.link(timeNodes[a][j], timeNodes[b][j + 1], k, D*k*k);
                    solver.link(timeNodes[b][j], timeNodes[a][j + 1], k, D*k*k);
                }
            }
        }
        long[] ret = solver.getMinCostMaxFlow(src, snk);
        out.println(ret[1]);
        out.flush();
    }

    public static class Node {
        // thou shall not create nodes except through addNode()
        private Node() { }

        List<Edge> edges = new ArrayList<Edge>();
        int index;          // index in nodes array

    }

    public static class Edge
    {
        boolean forward; // true: edge is in original graph
        Node from, to;   // nodes connected
        long flow;        // current flow
        final long capacity;
        Edge dual;      // reference to this edge's dual
        long cost;      // only used for MinCost.
        protected Edge(Node s, Node d, long c, boolean f)
        {
            forward = f;
            from = s;
            to = d;
            capacity = c;
        }
        long remaining() { return capacity - flow; }
        void addFlow(long amount) {
            flow += amount;
            dual.flow -= amount;
        }
    }

    public static abstract class MaxFlowSolver {
        List<Node> nodes = new ArrayList<Node>();

        public void link(Node n1, Node n2, long capacity) {
            link(n1, n2, capacity, 1);
        }

        public void link(Node n1, Node n2, long capacity, long cost) {
            Edge e12 = new Edge(n1, n2, capacity, true);
            Edge e21 = new Edge(n2, n1, 0, false);
            e12.dual = e21;
            e21.dual = e12;
            n1.edges.add(e12);
            n2.edges.add(e21);
            e12.cost = cost;
            e21.cost = -cost;
        }
        void link(int n1, int n2, long capacity) {
            link(nodes.get(n1), nodes.get(n2), capacity);
        }
        protected MaxFlowSolver(int n) {
            for (int i = 0; i < n; i++)
                addNode();
        }
        protected MaxFlowSolver() {
            this(0);
        }

        public abstract long getMaxFlow(Node src, Node snk);
        public Node addNode() {
            Node n = new Node();
            n.index = nodes.size();
            nodes.add(n);
            return n;
        }
    }
    static abstract class MinCostMaxFlowSolver extends MaxFlowSolver {
        // returns [maxflow, mincost]
        abstract long [] getMinCostMaxFlow(Node src, Node snk);
        // unavoidable boiler plate
        MinCostMaxFlowSolver ()      { this(0); }
        MinCostMaxFlowSolver (int n) { super(n); }
    }

    static class EdmondsKarp extends MinCostMaxFlowSolver
    {
        EdmondsKarp ()      { this(0); }
        EdmondsKarp (int n) { super(n); }
        long minCost;

        @Override
        public long [] getMinCostMaxFlow(Node src, Node snk) {
            long maxflow = getMaxFlow(src, snk);
            return new long [] { maxflow, minCost };
        }
        static final long INF = Long.MAX_VALUE/4;

        @Override
        public long getMaxFlow(Node src, Node snk) {
            final int n = nodes.size();
            final int source = src.index;
            final int sink = snk.index;
            long flow = 0;
            long cost = 0;
            long[] potential = new long[n]; // allows Dijkstra to work with negative edge weights
            while (true) {
                Edge[] parent = new Edge[n]; // used to store an augmenting path
                long[] dist = new long[n]; // minimal cost to vertex
                Arrays.fill(dist, INF);
                dist[source] = 0;
                PriorityQueue<Item> que = new PriorityQueue<Item>();
                que.add(new Item(0, source));
                while (!que.isEmpty()) {
                    Item item = que.poll();
                    if (item.dist != dist[item.v])
                        continue;

                    for (Edge e : nodes.get(item.v).edges) {
                        long temp = dist[item.v] + e.cost + potential[item.v] - potential[e.to.index];
                        if (e.capacity > e.flow && dist[e.to.index] > temp) {
                            dist[e.to.index] = temp;
                            parent[e.to.index] = e;
                            que.add(new Item(temp, e.to.index));
                        }
                    }
                }
                if (parent[sink] == null)
                    break;
                for (int i = 0; i < n; i++)
                    if (parent[i] != null)
                        potential[i] += dist[i];
                long augFlow = Long.MAX_VALUE;
                for (int i = sink; i != source; i = parent[i].from.index)
                    augFlow = Math.min(augFlow, parent[i].capacity - parent[i].flow);
                for (int i = sink; i != source; i = parent[i].from.index) {
                    Edge e = parent[i];
                    e.addFlow(augFlow);
                    cost += augFlow * e.cost;
                }
                flow += augFlow;
            }

            minCost = cost;
            return flow;
        }

        static class Item implements Comparable<Item> {
            long dist;
            int v;

            public Item(long dist, int v) {
                this.dist = dist;
                this.v = v;
            }

            public int compareTo(Item that) {
                return Long.compare(this.dist, that.dist);
            }
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


import java.io.*;
import java.util.*;
public class G{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
        class MinCostMaxFlow{
                ArrayList<Edge> al[];
                Edge ja[][];
                int d[]; // shortest distances
                int N , S , T , maxFlow ; int minCost;
                final int gmax = Integer.MAX_VALUE / 100;

                int edges = 0;

                class Edge{
                    int u , flow, rid, cost;
                    Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}
                }

                void addEdge(int u , int v , int flow , int cost){
                    int lu = al[u].size(), lv = al[v].size();
                    al[u].add(new Edge(v, flow, cost, lv));
                    al[v].add(new Edge(u, 0, -cost, lu));
                }

                void convertToArray(){
                    ja = new Edge[N][];
                    for(int i = 0; i < N; i++){
                        int sz = al[i].size();
                        ja[i] = new Edge[sz];
                        for(int j = 0; j < sz; j++){
                            ja[i][j] = al[i].get(j);
                        }
                        al[i].clear();
                    }
                }

                MinCostMaxFlow(int n , int source , int sink){
                    N = n; S = source; T = sink; maxFlow = 0; minCost = 0;
                    al = new ArrayList[N];
                    d = new int[N];
                    for(int i = 0; i < N; i++){
                        al[i] = new ArrayList<>();
                    }
                }

                boolean BellmanFord(boolean check){
                    d[0] = 0;
                    for(int i = 0; i < N - 1; i++){
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(e.flow == 0)continue; // not to consider reverse edges
                                d[e.u] = Math.min(d[e.u] , d[j] + e.cost);
                            }
                        }
                    }
                    if(check){// check for negative cycles
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(e.flow == 0)continue;
                                if(d[j] + e.cost < d[e.u]) return false;
                            }
                        }
                    }return true;
                }

                int node[]; // present node

                int visit[]; // 0 -> not added 1 -> not removed 2 -> removed
                int prv[], prve[]; // previous node for augmentation
                int dist[]; // min dist

                boolean simple(){
                    node = new int[N];
                    visit = new int[N];
                    prv = new int[N];
                    prve = new int[N];
                    dist = new int[N];   Arrays.fill(dist , gmax);

                    node[0] = S; dist[0] = 0;
                    int front = 1, back = 0;
                    while(front != back){
                        int u = node[back++]; int distu = dist[u];
                        if(back == N)back = 0;
                        visit[u] = 2;
                        for(int i = 0; i < ja[u].length; i++){
                            Edge e = ja[u][i];
                            if(e.flow == 0)continue;
                            int cdist = distu + e.cost; // no need of reduced cost
                            if(cdist < dist[e.u]){
                                if(visit[e.u] == 0){
                                    node[front] = e.u;
                                    if(++front == N)front = 0;
                                }else if(visit[e.u] == 2){
                                    if(--back == -1)back += N;
                                    node[back] = e.u;
                                }
                                visit[e.u] = 1;
                                prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;
                            }
                        }
                    }
                    return visit[T] != 0;
                }

                class pair{
                    int F; int S;
                    pair(int a, int b){F = a; S = b;}
                }

                boolean dijkstra(){
                    visit = new int[N];
                    prv = new int[N];
                    prve = new int[N];
                    dist = new int[N]; Arrays.fill(dist, gmax);
                    PriorityQueue<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));

                    pq.add(new pair(S , 0)); dist[0] = 0;
                    o : while(!pq.isEmpty()){
                        pair p = pq.poll();
                        while(dist[p.F] < p.S){
                            if(pq.isEmpty()) break o; // had a better val
                            p = pq.poll();
                        }
                        visit[p.F] = 2;
                        for(int i = 0; i < ja[p.F].length; i++){
                            Edge e = ja[p.F][i];
                            if(e.flow == 0)continue; // important
                            int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost
                            if(cdist < dist[e.u]){
                                if(visit[e.u] == 2) return false;
                                pq.add(new pair(e.u , cdist));
                                dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;
                                visit[e.u] = 1;
                            }
                        }
                    }
                    return visit[T] != 0;
                }

                int augment(){
                    int p = T; int min = gmax;
                    while(p != 0){
                        int pp = prv[p], pe = prve[p];
                        int val = ja[pp][pe].flow;
                        min = Math.min(min , val);
                        p = pp;
                    }
                    p = T;
                    while(p != 0){
                        int pp = prv[p], pe = prve[p];
                        ja[pp][pe].flow -= min;
                        ja[p][ja[pp][pe].rid].flow += min;
                        p = pp;
                    }
                    maxFlow += min;
                    return min;
                }

                // if(dist[T] >= 0)return true; // non contributing flow
                boolean calSimple(){
                    // uncomment to check for negative cycles
                    /* boolean possible = BellmanFord(true);
                     if(!possible) return false; */
                    while(simple()){
                        /*if(dist[T] >= 0)return true;*/
                        minCost += dist[T] * augment();
                    }
                    return true;
                }

                void updPotential(){
                    for(int i = 0; i < N; i++){
                        if(visit[i] != 0){
                            d[i] += dist[i] - dist[S];
                        }
                    }
                }
                boolean calWithPotential(){
                    // set true to check for negative cycles
                    // boolean possible = BellmanFord(false);
                    // if(!possible) return false;
                    while(dijkstra()){
                        int min = dist[T] + d[T] - d[S]; // getting back the original cost
                        /*if(dist[T] >= 0)return true;*/
                        minCost += min * augment();
                        updPotential();
                    }
                    return true;
                }
            }
            int n , m, k, c, d, a[], f[];
           public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();
            // S + n
            int maxl = 2 * n, T = n * maxl + 1;
            MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);
            a = new int[k + 1]; f = new int[n + 1];
            for(int i = 1; i <= k; i++){
                a[i] = in.nextInt();
                f[a[i]]++;
            }
            for(int i = 1; i <= n; i++){
                if(f[i] == 0)continue;
                ans.addEdge(0 , i , f[i], 0);
            }
            for(int i = 2; i <= n; i++){
                for(int l = 0; l < maxl - 1; l++){
                    ans.addEdge(l * n + i , (l + 1) * n + i, k, c);
                }
            }
            for(int i = 1; i <= m; i++){
                int a = in.nextInt(), b = in.nextInt();
                for(int l = 0; l < maxl - 1; l++){
                    for(int p = 1; p <= k; p++){
                        if(a != 1)
                            ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);
                        if(b != 1)
                            ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);
                    }
                }
            }
            for(int l = 1; l < maxl; l++){
                ans.addEdge(l * n + 1, T, k, 0);
            }
            ans.convertToArray();
            ans.calWithPotential();
            // ans.calSimple();
            if(ans.maxFlow != k){
                out.println("BUG");
            }else{
                out.println((int)ans.minCost);
            }
          }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.util.Scanner;
import sun.awt.X11.XConstants;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author root
 */
public class B {

    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String str[] = new String[4];
        for(int i = 0;i<4;i++){
            str[i] = in.next();
        }
        boolean type1 = false;
        boolean type2 = false;
        char [] seq1 = new char[2];
        char [] seq2 = new char[2];
        String str1 = str[0]+str[1].charAt(1)+str[1].charAt(0);
        str1 =str1.replaceAll("X", "");
        String str2 = str[2]+str[3].charAt(1)+str[3].charAt(0);
        str2 = str2.replaceAll("X", "");
        type1 = (str1.equals("ABC") || str1.equals("BCA") || str1.equals("CAB"));
        type2 = (str2.equals("ABC") || str2.equals("BCA") || str2.equals("CAB"));

        System.out.println((type1 == type2)?"YES":"NO");
    }
}


import java.io.*;
import java.util.*;

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);
        TaskA solver = new TaskA();
        solver.solve(in, out);
        out.close();
    }

    public static class TaskA {
        public void solve(InputReader in, PrintWriter out) {
            StringBuilder ar[] = new StringBuilder[2];
            for (int i = 0; i < 2; i++) {
                ar[i] = new StringBuilder();
                StringBuilder s1 = new StringBuilder(in.next());
                StringBuilder s2 = new StringBuilder(in.next());
                char rem = s2.charAt(0);
                s2.deleteCharAt(0);
                s2.append(rem);
                s1.append(s2);
                for (int k = 0; k < 4; k++)
                    if (s1.charAt(k) != 'X')
                        ar[i].append(s1.charAt(k));
            }
            for (int i = 0; i < 3; i++) {
                if (ar[0].compareTo(ar[1]) == 0) {
                    out.println("YES");
                    return;
                }
                char rem = ar[1].charAt(0);
                ar[1].deleteCharAt(0);
                ar[1].append(rem);
            }
            out.println("NO");
        }
    }

    public 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());
        }
    }
}


package crash_course.chapter1;

import java.io.*;
import java.util.*;

public class SlidingPuzzles {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(System.in);
		PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out)));

		ArrayList<String> slider1 = clockwiseArrangement(br);
		ArrayList<String> slider2 = clockwiseArrangement(br);

		slider1.remove("X");
		slider2.remove("X");

		slider2 = rotate(slider2, (slider2.indexOf("A") - slider1.indexOf("A")) % 4);

		if(Arrays.equals(slider1.toArray(), slider2.toArray())) {
			pw.write("YES");
		} else {
			pw.write("NO");
		}

		br.close();
		pw.close();
	}

	public static ArrayList<String> clockwiseArrangement(BufferedReader br) throws Exception {
		ArrayList<String> circle = new ArrayList<>();
		String line;

		line = br.readLine();
		circle.add(line.split("")[0]);
		circle.add(line.split("")[1]);
		line = br.readLine();
		circle.add(line.split("")[1]);
		circle.add(line.split("")[0]);

		return circle;
	}

	public static ArrayList<String> rotate(ArrayList<String> circle, int shift) {
		ArrayList<String> newCircle = new ArrayList<>();

		for(int i = 0; i < circle.size(); i++) {
			newCircle.add(circle.get((i + shift) % circle.size()));
		}

		return newCircle;
	}

}


import sun.plugin.javascript.navig.Array;

import java.util.*;

/**
 * Created by Ashiq on 6/10/2016.
 */
public class Zsort {
    public static void main(String[] args) {
         char [] c1=new char[4];
        char [] c2=new char[4];
        char a, b, c, x;
        Scanner s = new Scanner(System.in);
        a = (char) s.findInLine(".").charAt(0);
        b = (char) s.findInLine(".").charAt(0);
        s.nextLine();
        c = (char) s.findInLine(".").charAt(0);
        x = (char) s.findInLine(".").charAt(0);
        c1[0]=a;
        c1[1]=b;
        c1[2]=x;
        c1[3]=c;
        s.nextLine();
        a = (char) s.findInLine(".").charAt(0);
        b = (char) s.findInLine(".").charAt(0);
        s.nextLine();
        c = (char) s.findInLine(".").charAt(0);
        x = (char) s.findInLine(".").charAt(0);
        c2[0]=a;
        c2[1]=b;
        c2[2]=x;
        c2[3]=c;

        int n=0;
        for( int i=0;i<c2.length;i++)
        {
            if(c1[i]=='X')
            {
                n=i;
                break;
            }
        }
        int count=0;
        int d=0;
        while(count<64 && !c1.equals(c2))
        {
            if(n==c1.length-1)
            {
                c1[n]=c1[0];
                c1[0]='X';
                n=0;
            }
            else
            {
                c1[n]=c1[n+1];
                c1[n+1]='X';
                n++;
            }
            d=0;
            for (int i = 0; i < c2.length; i++) {
                if(c2[i]!=c1[i]) d=1;

            }
            if(d==0) break;
            count++;
        }

        if(d==0)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }

    }
}


import java.util.*;
public class Codeforces {
    public static void main(String[] args) {
     int som=0; int i=0;
        Scanner in=new Scanner(System.in);
        int a=in.nextInt();
        int j;
        for(j=0;j<10000000000;j++){
            String s=Integer.toString(j);
            som=0;
            for(int y=0;y<s.length();y++){
                som+=s.charAt(y)-48;
            }

            if(som==10){
              i++;
              if(i==a) break;
            }
        }
        System.out.println(j);
    }

}


import java.util.*;
public class PerfectNumbers {

	public static void main(String[] args) {
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int no;
		int sum=0;
		int c=0;String str;
		if(n<=10)
		{
		 c=10-n;
		 int num=n*10+c;
		 System.out.println(num);
		}else if(n>10) {
			str=String.valueOf(n);
			for(int i=0;i<str.length();i++) {
				sum=sum+(int)str.charAt(i)-(int)'0';
			}
			if(sum!=0){
			no=10-sum;
			String nn=String.valueOf(no);
			str=str+nn;
			System.out.println(str);

			}else if(sum==0){
			    System.out.println(str)
			}
		}

	}

}


import java.util.Scanner;

public class Main{
	public static void main(String args[]){
	Scanner sc = new Scanner(System.in)	;
      int n = sc.nextInt();
      for(long i = 19 ;i<1e18;i += 9){
       if(n == 1 && IsPerfect(i)){
          System.out.println(i) ;
         break;
}
        else {
       if(IsPerfect(i)){
n--;
}

}
}
	}
  public static boolean IsPerfect(long num){
int sum = 0;
    while(num != 0){
sum+=num%10;
      num /=10;


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int numero = n;
      int suma = 0;
      while(numero > 0) {
        suma += numero % 10;

        numero = numero / 10;

      }
      System.out.print(n*10 + (10-suma));*/

  }
}


import java.util.Scanner;
public class A158 {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		int[] x = new int[n];
		int counter = 0;
      for(int i=0; i<n; i++)
       {
         x[i]= scan.nextInt();
       }

      	for(int i=0;i<n;i++){

      	    if(x[k] == x[i] || x[k] > x[i]){
      	        counter ++;
      	    }

      	}
      	       System.out.println(counter) + 1;

        }
}


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public final class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner scan = new Scanner(System.in);
        int numpeople = scan.nextInt()
        int[] aryWin;
        aryWin = new int[numpeople]; // sets up array with "n" people

        int place = scan.nextInt(); // integer "place" = kth place

        for (int i=0, i<numpeople, i++) {    // fills array with scores of participants
            aryWin[i] = scan.nextInt();
            }
            int count=0;                        // count variable
        for (int b = 0, b<numpeople, b++) {
            if (aryWin[b] < aryWin[aryWin.length() - place - 1]) {
                count = count + 1;
        }
        System.out.println(count)
        }

        }
    }
}


import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n, max, temp;
    n= in.nextInt();
    max = in.nextInt();

    int c=0;

    int array[] = new int[n];

    for(int i=0; i<n; i++){
      array[i] = in.nextInt();
    }

    for(int i=0; i<n; i++){
      if(array[i] > max)  c++ else break;
    }

    System.out.println(c);

  }
}


//package com.company;
import java.io.IOException;
import java.util.Scanner;

public class NextRound {
    public static void main (String [] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int np = sc.nextInt();
        int k = sc.nextInt();
        int arrPlacement[] = new int[np];
        int advancement = 0;
      for(int i = 0; i < np; i ++){
          arrPlacement[i] = sc.nextInt();
          if(arrPlacement[i] > k) {
              if((arrPlacement[i]) > 0){
               advancement = advancement + 1;
           }
          else{
              advancement = advancement;
          }
//ooy
        }
        System.out.println(advancement);

    }
}


//package C;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.*;

public class solver implements Runnable {

	private void solve2(long n,long m,long a,long b) {
		/*long n=nextInt();
		long m=nextInt();
		long a=nextInt();
		long b=nextInt();*/

		if(m==1 || m==n) {out.print(1); return;}

		long to=a/m;
		if(to*m<a) to++;
		long td=b/m;
		if(td*m<b) td++;

		if(to==td) {out.print(1); return;}
		if(a%m==1 && b%m==0 ) {out.print(1); return;}
		if(a%m==1) {out.print(2); return;}
		if(b%m==0) {out.print(2); return;}
		if(b-a<=m) {out.print(2); return;}
		if( (b%m+1)%m==a%m) {out.print(2); return;}
		long tp=b/m;
		if(tp*m<b) tp++;
		long tr=a/m;
		if(tr*m<a) tr++;
		if(tp==tr+1)
			{out.print(2);

			return;
			}

		out.print(3);

	}
	public void solve() throws Exception{
		long n=nextLong();
		long m=nextLong();
		/*long n=49;
		long m=7;
		for(long b=13;b<=49;b++)
			solve2(n,m,13,b);*/
		long a=nextLong();
		long b=nextLong();
		if(n>=25) while(true); //(50,52)
		solve2(n,m,a,b);
	}

	public static void main(String[] args) {

		new solver().run();
	}

	BufferedReader in;
	StringTokenizer tokenizer;
	PrintWriter out;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			//in = new BufferedReader(new FileReader("in.txt"));
			tokenizer = null;
			out = new PrintWriter(System.out);
			//out = new PrintWriter(new File("out.txt"));
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}
}


import java.util.Scanner;

/**
 *
 * @author Andrew
 */
public class C {

    public static boolean poln(int i, int[][] mas) {
        for (int j = 0; j < mas[0].length; j++) {
            if (mas[i][j] == 1) {
                return true;
            }
        }
        return false;
    }

    public static boolean eq(int i, int[][] mas) {
        if ((i == 0) && (poln(0, mas))) {
            return false;
        }
        if ((i == 0) && (!poln(0, mas))) {
            return true;
        }
        for (int j = 0; j < mas[0].length; j++) {
            if (((mas[i][j] != mas[i - 1][j])) && (mas[i][j] != 2)) {
                return false;
            }
        }
        return true;
    }

    public static int number(int[][] mas, int u) {
        int t = 0;
        int k = 0;
        for (int i = 0; i < mas.length; i++) {
            if ((poln(i, mas)) || (i == 0)) {
                if (!eq(i, mas)) {
                    k = 1;
                    t++;
                }
            }
            if ((!poln(i, mas)) && (k == 1) && (i != 0) && (u == 1)) {
                return t;
            }

        }
        return t;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int tt;
        if (n % m == 0) {
            tt = n / m;
        } else {
            tt = n / m + 1;
        }

        int[][] mas = new int[tt][m];
        int[][] mas2 = new int[m][tt];

        for (int i = 0; i < tt; i++) {
            for (int j = 0; j < m; j++) {
                if (((i * m + j) >= a - 1) && ((i * m + j) <= b - 1)) {
                    mas[i][j] = 1;
                    mas2[j][i] = 1;

                }
                if ((i * m + j) >= n) {
                    mas[i][j] = 2;
                    mas2[j][i] = 2;
                }
            }
        }

        int t1 = number(mas, 1);
        int t2 = number(mas2, 0);
        if (t1 < t2) {
            System.out.print(t1);
        } else {
            System.out.print(t2);
        }

    }
}


import java.io.*;

import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final String filename = "";

	public void solve() throws Exception {
		int n = iread();
		int m = iread();
		int a = iread() - 1;
		int b = iread() - 1;
		int res = 0;
		if (a / m == b / m)
			res = 1;
		else if (a % m == 0) {
			if (b % m == m - 1 || b == n - 1)
				res = 1;
			else
				res = 2;
		} else if (b == n - 1||b%m=m-1) {
			if (a % m == 0)
				res = 1;
			else
				res = 2;
		} else {
			if (a / m == b / m - 1 || a % m + b % m == m - 1)
				res = 2;
			else
				res = 3;
		}
		out.write(res + "");
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {
		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		// new Thread(new Main()).start();
		new Thread(null, new Main(), "1", 1 << 25).start();
	}
}


import static java.lang.Math.*;
import java.util.*;
import java.io.*;

public class C {

    public void solve() throws Exception {

        long n = nextInt(), m = nextInt(), a = nextInt()-1, b = nextInt()-1;
        long la = a/m, lb = b/m, fa = a%m, fb = (b+1)%m;
        if (b+1==n) b = (lb+1)*m-1;

        if (la==lb || (fa==0 && fb==0)) println(1);
        else if (la+1==lb || fa==0 || fb==0 || fa==fb) println(2);
        else println(3);
        a
    }

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

    boolean showDebug = true;

    double EPS = 1e-7;
    int INF = Integer.MAX_VALUE;
    long INFL = Long.MAX_VALUE;
    double INFD = Double.MAX_VALUE;

    int absPos(int i) {
        return i<0 ? 0:i;
    }
    long absPos(long i) {
        return i<0 ? 0:i;
    }
    double absPos(double i) {
        return i<0 ? 0:i;
    }

    int min(int... nums) {
        int r = INF;
        for (int i: nums)
            if (i<r) r=i;
        return r;
    }
    int max(int... nums) {
        int r = -INF;
        for (int i: nums)
            if (i>r) r=i;
        return r;
    }
    long minL(long... nums) {
        long r = INFL;
        for (long i: nums)
            if (i<r) r=i;
        return r;
    }
    long maxL(long... nums) {
        long r = -INFL;
        for (long i: nums)
            if (i>r) r=i;
        return r;
    }
    double minD(double... nums) {
        double r = INFD;
        for (double i: nums)
            if (i<r) r=i;
        return r;
    }
    double maxD(double... nums) {
        double r = -INFD;
        for (double i: nums)
            if (i>r) r=i;
        return r;
    }
    long sumArr(int[] arr) {
        long res = 0;
        for (int i: arr)
            res+=i;
        return res;
    }
    long sumArr(long[] arr) {
        long res = 0;
        for (long i: arr)
            res+=i;
        return res;
    }
    double sumArr(double[] arr) {
        double res = 0;
        for (double i: arr)
            res+=i;
        return res;
    }

    long partsFitCnt(long partSize, long wholeSize) {
        return (partSize+wholeSize-1)/partSize;
    }

    boolean odd(long i) {
        return (i&1)==1;
    }

    long binpow(int x, int n) {
        long r = 1;
        while (n>0) {
            if ((n&1)!=0) r*=x;
            x*=x;
            n>>=1;
        }
        return r;
    }

    String str(Object o) {
        return o.toString();
    }

    long timer = System.currentTimeMillis();
    void startTimer() {
        timer = System.currentTimeMillis();
    }
    void stopTimer() {
        System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
    }

    class InputReader {
        byte[] buf = new byte[1<<16];
        int bufPos = 0, bufLim = -1;
        char read() throws IOException {
            if (bufPos>=bufLim) {
                bufLim = System.in.read(buf);
                bufPos = 0;
            }
            return (char)buf[bufPos++];
        }
    }

    InputReader in = new InputReader();
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);

    char nextInput() throws IOException {
        return in.read();
    }
    char nextChar() throws IOException {
        char c = in.read();
        while (c<=' ') c=in.read();
        return c;
    }
    String nextWord() throws IOException {
        StringBuilder sb = new StringBuilder();
        char c = in.read();
        while (c<=' ') c=in.read();
        while (c>' ') {
            sb.append(c);
            c = in.read();
        }
        return new String(sb);
    }
    String nextLine() throws IOException {
        StringBuilder sb = new StringBuilder();
        char c = in.read();
        while (c<=' ') c=in.read();
        while (c!='\n' && c!='\r') {
            sb.append(c);
            c = in.read();
        }
        return new String(sb);
    }
    int nextInt() throws IOException {
        int r = 0;
        char c = nextChar();
        boolean neg = false;
        if (c=='-') neg=true;
        else r = c-48;
        c = nextInput();
        while (c>='0' && c<='9') {
            r*=10;
            r+=c-48;
            c=nextInput();
        }
        return neg ? -r:r;
    }
    long nextLong() throws IOException {
        long r = 0;
        char c = nextChar();
        boolean neg = false;
        if (c=='-') neg=true;
        else r = c-48;
        c = nextInput();
        while (c>='0' && c<='9') {
            r*=10L;
            r+=c-48L;
            c=nextInput();
        }
        return neg ? -r:r;
    }
    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextWord());
    }
    int[] nextArr(int size) throws NumberFormatException, IOException {
        int[] arr = new int[size];
        for (int i=0; i<size; i++)
            arr[i] = nextInt();
        return arr;
    }
    long[] nextArrL(int size) throws NumberFormatException, IOException {
        long[] arr = new long[size];
        for (int i=0; i<size; i++)
            arr[i] = nextLong();
        return arr;
    }
    double[] nextArrD(int size) throws NumberFormatException, IOException {
        double[] arr = new double[size];
        for (int i=0; i<size; i++)
            arr[i] = nextDouble();
        return arr;
    }
    String[] nextArrS(int size) throws NumberFormatException, IOException {
        String[] arr = new String[size];
        for (int i=0; i<size; i++)
            arr[i] = nextWord();
        return arr;
    }
    char[] nextArrCh(int size) throws IOException {
        char[] arr = new char[size];
        for (int i=0; i<size; i++)
            arr[i] = nextChar();
        return arr;
    }
    char[][] nextArrCh(int rows, int columns) throws IOException {
        char[][] arr = new char[rows][columns];
        for (int i=0; i<rows; i++)
            for (int j=0; j<columns; j++)
                arr[i][j] = nextChar();
        return arr;
    }

    void print(Object o) throws IOException {
        out.write(o.toString());
    }
    void println(Object o) throws IOException {
        out.write(o.toString());
        out.newLine();
    }
    void print(Object... o) throws IOException {
        for (int i=0; i<o.length; i++) {
            if (i!=0) out.write(' ');
            out.write(o[i].toString());
        }
    }
    void println(Object... o) throws IOException {
        print(o);
        out.newLine();
    }
    void printn(Object o, int n) throws IOException {
        String s = o.toString();
        for (int i=0; i<n; i++) {
            out.write(s);
            if (i!=n-1) out.write(' ');
        }
    }
    void printnln(Object o, int n) throws IOException {
        printn(o, n);
        out.newLine();
    }
    void printArr(int[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(Integer.toString(arr[i]));
        }
    }
    void printArr(long[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(Long.toString(arr[i]));
        }
    }
    void printArr(double[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(Double.toString(arr[i]));
        }
    }
    void printArr(String[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(arr[i]);
        }
    }
    void printArr(char[] arr) throws IOException {
        for (char c: arr) out.write(c);
    }
    void printlnArr(int[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }
    void printlnArr(long[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }
    void printlnArr(double[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }
    void printlnArr(String[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }
    void printlnArr(char[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }

    void debug(Object... o) {
        if (showDebug) System.err.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) throws Exception {
        Locale.setDefault(Locale.US);
        new C().solve();
        out.flush(); out.close();
    }
}


import java.util.*;
import java.lang.*;

public class Backtracking {

    static char[] chars;
    public static void main(String[] args) {
        Scanner io = new Scanner(System.in);
        int N = io.nextInt();
        Set<Integer> tmp = new HashSet<>();
        for(int i = 0; i < N; i++) tmp.add(io.nextInt());
        Integer arr[] = new Integer[tmp.size()];
        tmp.toArray(arr);
        Arrays.sort(arr);
        if(arr.length > 3) { System.out.println(-1); return; }
        if(arr.length == 1) { System.out.println(0); return; }
        if(arr.length == 2) {
            if((arr[0] + arr[1]) % 2 == 0)
                System.out.println(arr[1] - (arr[0] + arr[1]) / 2);
            else
                System.out.println(arr[1] - arr[0]);
            return;
        }
        if((arr[2] + arr[0]) / 2.0) % 1 != 0 || Arrays.binarySearch(arr, (arr[2] + arr[0]) / 2) < 0) System.out.println(-1);
        else System.out.println(arr[2] - arr[1]);
    }
    public static int summ(Integer[] arr) {
        int sum = 0;
        for(int a: arr) sum += a;
        return sum;
    }
}


package ce1002.a5.s107502516;

import java.util.Scanner;

public class a5 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int num = input.nextInt();
		int[] arr = new int[num];
		for (int i = 0; i < num; i++) {
			arr[i] = input.nextInt();
		}
		int max = -10000000;
		int min = 10000000;
		int flag = 0;
		for (int i = 0; i < num; i++) {
			if (arr[i] > max) {
				max = arr[i];
			}
			if (arr[i] < min) {
				min = arr[i];
			}
		}

		int a = arr[0];
		for (int i = 0; i < num; i++) {
			if (arr[i] != a) {
				flag = 0;
				break;
			}
			if (arr[i] == a) {
				if (i == num - 1) {
					flag = 1;
					System.out.print(0);
				}
			}
		}
		if (flag == 0) {
			int b = max;
			for (int i = 0; i < num; i++) {
				if (arr[i] != a && arr[i] != b) {
					flag = 0;
					break;
				}
				if (i == num - 1) {
					flag = 1;
					if ((int) ((min + max) / 2) - (float) ((min + max) / 2) == 0) {
						System.out.print(max-(max - min)/2);
					}
					else {
						System.out.print(max - min);
				}
			}
		}
		if (flag == 0) {
			if ((int) ((min + max) / 2) - (float) ((min + max) / 2) != 0) {
				flag = 1;
			}
			if (flag == 0) {
				int c = (min + max) / 2;
				for (int i = 0; i < num; i++) {
					if (arr[i] != a && arr[i] != max && arr[i] != c) {
						flag = 0;
						System.out.print(-1);
						break;
					}
					if (i==num-1) {

						System.out.print(max-c);
					}
				}
			}
		}
	}
}


import java.io.BufferedReader;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

import lCALE.A;

			public class MMAIN {

					static final int MAX = (int)1e5;
					public static void main(String[] args) throws FileNotFoundException {

							MyScanner scanner = new MyScanner();
							PrintWriter out = new PrintWriter(System.out);

							int n = scanner.nextInt();
							int[] a = new int[n];

							int[] b = new int[101];
							for(int i = 0; i < n; ++i) {
								a[i] = scanner.nextInt();
							}

							loop:
							for(int i = 0; i < n; ++i) {

								int d = -1;
								for(int j = 0; j < n ; ++j) {
									if(a[i] == a[j]) continue;
									else if(d == -1) {
										d = Math.abs(a[i] - a[j]);
									}else {
										if(Math.abs(a[i] - a[j]) != Math.abs(d)) {
											continue loop;
										}
									}
								}

								System.out.println(Math.abs(d));
								return;
							}

							System.out.println(-1);

							out.close();
					}

					static class MyScanner {
								BufferedReader br;
								StringTokenizer st;

								public MyScanner() throws FileNotFoundException {
								  // br = new BufferedReader	(new InputStreamReader(new FileInputStream("input.txt")));
									br = new BufferedReader(new InputStreamReader(System.in));
								}

								String next() {
									while (st == null || !st.hasMoreElements()) {
										try {
											st = new StringTokenizer(br.readLine());
										} catch (IOException e) {
											e.printStackTrace();
										}
									}
									return st.nextToken();
								}

								int nextInt() {
									return Integer.parseInt(next());
								}

								long nextLong() {
									return Long.parseLong(next());
								}

								double nextDouble() {
									return Double.parseDouble(next());
								}

								String nextLine() {
									String str = "";
									try {
										str = br.readLine();
									} catch (IOException e) {
										e.printStackTrace();
									}
									return str;
								}
							}
					}


/*
 * Assignment 5
 * Course: ce1002
 * Name: ���θ�
 * Student ID: 107502536
 */

package ce1002.a5.s107502536;

import java.util.Scanner;

public class a5 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println(new DaShu("000").getString());
        System.out.println(new DaShu("+000000000").getString());
        System.out.println(new DaShu("-000000000").getString());
        System.out.println(new DaShu("-000078763").getString());
        System.out.println(new DaShu("111111111111").plus(new DaShu("2222222222222")).getString());
        System.out.println(new DaShu("33333333333333").minus(new DaShu("444444444444444")).getString());
        while(true) {
        	  String s1 = input.next();if (s1.contains("exit")) {break;}   //terminated condition
        	  String s2 = input.next();if (s2.contains("exit")) {break;}
        	  String s3 = input.next();if (s3.contains("exit")) {break;}
        	  if (s2.compareTo("+")==0) {   //plus method
        		  System.out.println(new DaShu(s1).plus(new DaShu(s3)).getString());
        	  }
              if (s2.compareTo("-")==0) {   //minus method
            	  System.out.println(new DaShu(s1).minus(new DaShu(s3)).getString());
        	  }
        }

	}

}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.lang.*;

public class P750F{
	static long mod=1000000007;
	static InputReader in = new InputReader(System.in);
	static ArrayList<Integer>ar1=new ArrayList<Integer>();
	static ArrayList<Integer>ar2=new ArrayList<Integer>();
	static ArrayList<Integer>ar[]=new ArrayList[200];
	static HashSet<Integer>hs=new HashSet<Integer>();
	static int ans=-1;
	static void swap()
	{
		ArrayList<Integer>t1=new ArrayList<Integer>();
			ArrayList<Integer>t2=new ArrayList<Integer>();
			for(int cc:ar1)
			{
				t1.add(cc);
			}
			for(int cc:ar2)
			{
				t2.add(cc);
			}
			ar1=new ArrayList<Integer>();
			ar2=new ArrayList<Integer>();
			for(int cc:t1)
			{
				ar2.add(cc);
			}
			for(int cc:t2)
			{
				ar1.add(cc);
			}
	}
	static void l1()
	{
		l2();
	}
	static void l2()
	{
	 int y=in.readInt();
   	 System.out.println("? "+y);
   	 hs.add(y);
   	 int z=in.readInt();
   	if(z==2)
   	{
   		int bb1=in.readInt();
   		int bb2=in.readInt();
   		System.out.println("! "+y);
   	}
   	else
   	{

   		int x1=in.readInt();
   		int x2=in.readInt();
   		int x3=in.readInt();
   		ar[y].add(x1);
   		ar[y].add(x2);
   		ar[y].add(x3);
   		int f=0;
   		if(!hs.contains(x1))
   		{
   			f=1;
   			dfs1(x1);

   		}
   		if(!hs.contains(x2)&&ans==-1)
   		{
   			if(f==0)
   				dfs1(x2);
   			else
   				dfs2(x2);
   		}
   		if(!hs.contains(x3)&&ans==-1)
   		{
   			dfs2(x3);
   		}
   		if(ans!=-1)
   		{
   			System.out.println("! "+ans);
   		}
   		else
   		{
   			int s1=ar1.size();
   			int s2=ar2.size();
   			if(s1<s2)
   			{
   				swap();
   			}
   			s1=ar1.size();
   			s2=ar2.size();
   				int d=s1-s2;
   				d/=2;
   				int l=s2+d;
   				l++;
   				if(l>=4)
   				{
   					if(l==4)
   					{
   						l4(0);
   					}
   					else if(l==5)
   					{
   						l5(0);
   					}
   					else
   					{
   						l6(0);
   					}
   				}
   				else
   				{
   					l3(0);
   				}

   		}

   	}
	}
	static void l3(int u)
	{
		int x1,x2,x3,z,f;
		int ele=ar1.get((0+u));
		ar1=new ArrayList<Integer>();
		ar2=new ArrayList<Integer>();
		int cur=-1;
		for(int j1=0;j1<ar[ele].size();j1++)
		{
			int p=ar[ele].get(j1);
			if(!hs.contains(p))
			{
				cur=p;
			}
		}
		hs.add(cur);
		System.out.println("? "+cur);
    	 z=in.readInt();
    	if(z==2)
    	{
    		int bb1=in.readInt();
       		int bb2=in.readInt();
    		System.out.println("! "+cur);
    	}
    	else
    	{
    		x1=in.readInt();
    		x2=in.readInt();
    		x3=in.readInt();
    		ar[cur].add(x1);
    		ar[cur].add(x2);
    		ar[cur].add(x3);

		f=0;
		if(!hs.contains(x1))
		{
			f=x1;
			dfs1(x1);
		}
		if(!hs.contains(x2))
		{
			if(f==0)
				{
					f=x2;
					dfs1(x2);
				}
		}
		if(ans!=-1)
		{
			System.out.println("! "+ans);
		}
		else
		{
		if(ar1.size()==3)
		{
			int curr=-1;
			for(int j1=0;j1<ar[cur].size();j1++)
			{
				int p=ar[cur].get(j1);
				if(!hs.contains(p))
				{
					curr=p;
				}
			}
			hs.add(curr);
			System.out.println("? "+curr);
       	 z=in.readInt();
       	if(z==2)
       	{
       		int bb1=in.readInt();
       		int bb2=in.readInt();
       		System.out.println("! "+curr);
       	}
       	else
       	{
       		x1=in.readInt();
    		x2=in.readInt();
    		x3=in.readInt();
       		ar[curr].add(x1);
    		ar[curr].add(x2);
    		ar[curr].add(x3);
    		f=0;
    		if(!hs.contains(x1))
    		{
    			f=1;
    			System.out.println("? "+x1);
    			hs.add(x1);
    			 z=in.readInt();
   		        	if(z==2)
   		        	{
   		        		int bb1=in.readInt();
   		        		int bb2=in.readInt();

   		        		ans=x1;
   		        		System.out.println("! "+x1);
   		        	}
   		        	else
   		        	{
   		        		int xx1=in.readInt();
		        		int xx2=in.readInt();
		        		int xx3=in.readInt();
		        		if(!hs.contains(xx1))
		        		{
		        			System.out.println("? "+xx1);
		        			hs.add(xx1);
		        			 z=in.readInt();
	           		        	if(z==2)
	           		        	{
	           		        		int bb1=in.readInt();
	           		        		int bb2=in.readInt();
	           		        		ans=xx1;
	           		        		System.out.println("! "+xx1);
	           		        	}
	           		        	else
	           		        	{
	           		        		int bb1=in.readInt();
	           		        		int bb2=in.readInt();
	           		        		int bb3=in.readInt();
	           		        	}
		        		}
		        		if(!hs.contains(xx2)&&ans==-1)
		        		{

		        			System.out.println("? "+xx2);
		        			hs.add(xx2);
		        			 z=in.readInt();
	           		        	if(z==2)
	           		        	{
	           		        		int bb1=in.readInt();
	           		        		int bb2=in.readInt();
	           		        		ans=xx2;
	           		        		System.out.println("! "+xx2);
	           		        	}
	           		        	else
	           		        	{
	           		        		int bb1=in.readInt();
	           		        		int bb2=in.readInt();
	           		        		int bb3=in.readInt();
	           		        	}
		        		}
		        		if(!hs.contains(xx3)&&ans==-1)
		        		{

		        			System.out.println("? "+xx3);
		        			hs.add(xx3);
		        			 z=in.readInt();
	           		        	if(z==2)
	           		        	{
	           		        		int bb1=in.readInt();
	           		        		int bb2=in.readInt();
	           		        		ans=xx3;
	           		        		System.out.println("! "+xx3);
	           		        	}
	           		        	else
	           		        	{
	           		        		int bb1=in.readInt();
	           		        		int bb2=in.readInt();
	           		        		int bb3=in.readInt();
	           		        	}
		        		}
   		        	}
    		}
    		if(!hs.contains(x2)&&ans==-1)
    		{
    			if(f==0)
    			{
    				f=1;
        			System.out.println("? "+x2);
        			hs.add(x2);
        			 z=in.readInt();
       		        	if(z==2)
       		        	{
       		        		int bb1=in.readInt();
       		        		int bb2=in.readInt();
       		        		ans=x2;
       		        		System.out.println("! "+x2);
       		        	}
       		        	else
       		        	{
       		        		int xx1=in.readInt();
    		        		int xx2=in.readInt();
    		        		int xx3=in.readInt();
    		        		if(!hs.contains(xx1))
    		        		{
    		        			System.out.println("? "+xx1);
    		        			hs.add(xx1);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx1;
    	           		        		System.out.println("! "+xx1);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
    		        		if(!hs.contains(xx2)&&ans==-1)
    		        		{

    		        			System.out.println("? "+xx2);
    		        			hs.add(xx2);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx2;
    	           		        		System.out.println("! "+xx2);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
    		        		if(!hs.contains(xx3)&&ans==-1)
    		        		{

    		        			System.out.println("? "+xx3);
    		        			hs.add(xx3);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx3;
    	           		        		System.out.println("! "+xx3);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
       		        	}
    			}
    			else
    			{
    				f=1;
        			System.out.println("? "+x2);
        			hs.add(x2);
        			 z=in.readInt();
       		        	if(z==2)
       		        	{
       		        		int bb1=in.readInt();
       		        		int bb2=in.readInt();
       		        		ans=x2;
       		        		System.out.println("! "+x2);
       		        	}
       		        	else
       		        	{
       		        		int xx1=in.readInt();
    		        		int xx2=in.readInt();
    		        		int xx3=in.readInt();
    		        		int g=0;
    		        		if(!hs.contains(xx1))
    		        		{
    		        			g=1;
    		        			System.out.println("? "+xx1);
    		        			hs.add(xx1);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx1;
    	           		        		System.out.println("! "+xx1);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
    		        		if(!hs.contains(xx2)&&ans==-1)
    		        		{
    		        			if(g==0)
    		        			{
    		        				g=1;
    		        			System.out.println("? "+xx2);
    		        			hs.add(xx2);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx2;
    	           		        		System.out.println("! "+xx2);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        			}
    		        			else
    		        			{
    		        				ans=xx2;
    		        				System.out.println("! "+xx2);
    		        			}
    		        		}
    		        		if(!hs.contains(xx3)&&ans==-1)
    		        		{

    	           		        		ans=xx3;
    	           		        		System.out.println("! "+xx3);
    		        		}
       		        	}
    			}
    		}
    		if(!hs.contains(x3)&&ans==-1)
    		{
    			if(f==0)
    			{
    				f=1;
        			System.out.println("? "+x3);
        			hs.add(x3);
        			 z=in.readInt();
       		        	if(z==2)
       		        	{
       		        		int bb1=in.readInt();
       		        		int bb2=in.readInt();
       		        		ans=x3;
       		        		System.out.println("! "+x3);
       		        	}
       		        	else
       		        	{
       		        		int xx1=in.readInt();
    		        		int xx2=in.readInt();
    		        		int xx3=in.readInt();
    		        		if(!hs.contains(xx1))
    		        		{
    		        			System.out.println("? "+xx1);
    		        			hs.add(xx1);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx1;
    	           		        		System.out.println("! "+xx1);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
    		        		if(!hs.contains(xx2)&&ans==-1)
    		        		{

    		        			System.out.println("? "+xx2);
    		        			hs.add(xx2);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx2;
    	           		        		System.out.println("! "+xx2);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
    		        		if(!hs.contains(xx3)&&ans==-1)
    		        		{

    		        			System.out.println("? "+xx3);
    		        			hs.add(xx3);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx3;
    	           		        		System.out.println("! "+xx3);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
       		        	}
    			}
    			else
    			{
    				f=1;
        			System.out.println("? "+x3);
        			hs.add(x3);
        			 z=in.readInt();
       		        	if(z==2)
       		        	{
       		        		int bb1=in.readInt();
       		        		int bb2=in.readInt();
       		        		ans=x3;
       		        		System.out.println("! "+x3);
       		        	}
       		        	else
       		        	{
       		        		int xx1=in.readInt();
    		        		int xx2=in.readInt();
    		        		int xx3=in.readInt();
    		        		int g=0;
    		        		if(!hs.contains(xx1))
    		        		{
    		        			g=1;
    		        			System.out.println("? "+xx1);
    		        			hs.add(xx1);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx1;
    	           		        		System.out.println("! "+xx1);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        		}
    		        		if(!hs.contains(xx2)&&ans==-1)
    		        		{
    		        			if(g==0)
    		        			{
    		        				g=1;
    		        			System.out.println("? "+xx2);
    		        			hs.add(xx2);
    		        			 z=in.readInt();
    	           		        	if(z==2)
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		ans=xx2;
    	           		        		System.out.println("! "+xx2);
    	           		        	}
    	           		        	else
    	           		        	{
    	           		        		int bb1=in.readInt();
    	           		        		int bb2=in.readInt();
    	           		        		int bb3=in.readInt();
    	           		        	}
    		        			}
    		        			else
    		        			{
    		        				ans=xx2;
    		        				System.out.println("! "+xx2);
    		        			}
    		        		}
    		        		if(!hs.contains(xx3)&&ans==-1)
    		        		{

    	           		        		ans=xx3;
    	           		        		System.out.println("! "+xx3);
    		        		}
       		        	}
    			}
    		}
    		f=0;

       	}
		}
		else
		{
			if(ar1.size()==5)
			{
				ele=ar1.get(0);
				hs.add(ele);
				cur=-1;
				for(int zz:ar[ele])
				{
					if(!hs.contains(zz))
					{
						cur=zz;
						break;
					}
				}
				System.out.println("? "+cur);
				hs.add(cur);
				z=in.readInt();
				if(z==2)
				{
					int bb1=in.readInt();
			   		int bb2=in.readInt();
					System.out.println("! "+cur);
				}
				else
				{
					x1=in.readInt();
					x2=in.readInt();
					x3=in.readInt();
					if(!hs.contains(x1)&&ans==-1)
					{
						System.out.println("? "+x1);
        				hs.add(x1);
        				z=in.readInt();
        				if(z==2)
        				{
        					int bb1=in.readInt();
        			   		int bb2=in.readInt();
        					ans=x1;
        					System.out.println("! "+x1);
        				}
        				else
       		        	{
       		        		int bb1=in.readInt();
       		        		int bb2=in.readInt();
       		        		int bb3=in.readInt();
       		        	}
					}
					if(!hs.contains(x2)&&ans==-1)
					{
						System.out.println("? "+x2);
        				hs.add(x2);
        				z=in.readInt();
        				if(z==2)
        				{
        					int bb1=in.readInt();
        			   		int bb2=in.readInt();
        					ans=x2;
        					System.out.println("! "+x2);
        				}
        				else
       		        	{
       		        		int bb1=in.readInt();
       		        		int bb2=in.readInt();
       		        		int bb3=in.readInt();
       		        	}
					}
					if(!hs.contains(x3)&&ans==-1)
					{
						System.out.println("? "+x3);
        				hs.add(x3);
        				z=in.readInt();
        				if(z==2)
        				{
        					int bb1=in.readInt();
        			   		int bb2=in.readInt();
        					ans=x3;
        					System.out.println("! "+x3);
        				}
        				else
       		        	{
       		        		int bb1=in.readInt();
       		        		int bb2=in.readInt();
       		        		int bb3=in.readInt();
       		        	}
					}
				}
			}
			else
			{
				ele=ar1.get(1);
				hs.add(ele);
				for(int zz:ar[ele])
				{
					if(!hs.contains(zz))
					{
						ans=zz;
						System.out.println("! "+zz);
						break;
					}
				}
			}
		}
		}
	}
	}
	static void l4(int u)
	{
		int x1,x2,x3,z,f;
		int ele=ar1.get((1+u));
		hs.add(ele);
		int cur=-1;
		for(int j1=0;j1<ar[ele].size();j1++)
		{
			int p=ar[ele].get(j1);
			if(!hs.contains(p))
			{
				cur=p;
			}
		}
		hs.add(cur);
		System.out.println("? "+cur);
    	 z=in.readInt();
    	if(z==2)
    	{
    		int bb1=in.readInt();
       		int bb2=in.readInt();
    		System.out.println("! "+cur);
    	}
    	else
    	{
    		x1=in.readInt();
			x2=in.readInt();
			x3=in.readInt();
			ar[cur].add(x1);
			ar[cur].add(x2);
			ar[cur].add(x3);
			ar1=new ArrayList<Integer>();
			ar2=new ArrayList<Integer>();
			f=0;
			if(ans==-1&&!hs.contains(x1))
			{
				f=1;
				dfs1(x1);
			}
			if(ans==-1&&!hs.contains(x2)&&f==0)
			{
				f=1;
				dfs1(x2);
			}
			if(ans==-1&&!hs.contains(x3)&&f==0)
			{
				f=1;
				dfs1(x3);
			}
			if(ans!=-1)
			{
				System.out.println("! "+ans);

			}
			else
			{
				int s=ar1.size();
				int curr=-1;
				if(ar1.size()==4)
				{
					for(int j=0;j<ar[cur].size();j++)
					{
						int zz=ar[cur].get(j);
						if(!hs.contains(zz))
						{
							curr=zz;
						}
					}

				hs.add(curr);
				System.out.println("? "+curr);
				z=in.readInt();
				if(z==2)
				{
					int bb1=in.readInt();
			   		int bb2=in.readInt();
					System.out.println("! "+curr);
				}
				else
				{
				x1=in.readInt();
				x2=in.readInt();
				x3=in.readInt();
				ar[curr].add(x1);
				ar[curr].add(x2);
				ar[curr].add(x3);
				if(ans==-1&&!hs.contains(x1))
				{
					System.out.println("? "+x1);
					z=in.readInt();
					if(z==2)
					{
						int bb1=in.readInt();
				   		int bb2=in.readInt();
						ans=x1;
						System.out.println("! "+x1);
					}
					else
   		        	{
   		        		int bb1=in.readInt();
   		        		int bb2=in.readInt();
   		        		int bb3=in.readInt();
   		        	}
				}
				if(ans==-1&&!hs.contains(x2))
				{
					System.out.println("? "+x2);
					z=in.readInt();
					if(z==2)
					{
						int bb1=in.readInt();
				   		int bb2=in.readInt();
						ans=x2;
						System.out.println("! "+x2);
					}
					else
   		        	{
   		        		int bb1=in.readInt();
   		        		int bb2=in.readInt();
   		        		int bb3=in.readInt();
   		        	}
				}
				if(ans==-1&&!hs.contains(x3))
				{
					System.out.println("? "+x3);
					z=in.readInt();
					if(z==2)
					{
						int bb1=in.readInt();
				   		int bb2=in.readInt();
						ans=x3;
						System.out.println("! "+x3);
					}
					else
   		        	{
   		        		int bb1=in.readInt();
   		        		int bb2=in.readInt();
   		        		int bb3=in.readInt();
   		        	}
				}
				}
				}
				else
				{
					ele=ar1.get(0);
					hs.add(ele);
					for(int xx:ar[ele])
					{
						if(!hs.contains(xx))
						{
							ans=xx;
							System.out.println("! "+xx);
							break;
						}
					}
				}
			}
    	}
	}
	static void l5(int u)
	{
		int x1,x2,x3,z,f;
		int ele=ar1.get((2+u));
		hs.add(ele);
		int cur=-1;
		for(int zz:ar[ele])
		{
			if(!hs.contains(zz))
			{
				cur=zz;
				break;
			}
		}
		System.out.println("? "+cur);
		hs.add(cur);
		z=in.readInt();
		if(z==2)
		{
			int bb1=in.readInt();
	   		int bb2=in.readInt();
			System.out.println("! "+cur);
		}
		else
		{
			x1=in.readInt();
			x2=in.readInt();
			x3=in.readInt();
			if(!hs.contains(x1)&&ans==-1)
			{
				System.out.println("? "+x1);
				hs.add(x1);
				z=in.readInt();
				if(z==2)
				{
					int bb1=in.readInt();
			   		int bb2=in.readInt();
					ans=x1;
					System.out.println("! "+x1);
				}
				else
		        	{
		        		int bb1=in.readInt();
		        		int bb2=in.readInt();
		        		int bb3=in.readInt();
		        	}
			}
			if(!hs.contains(x2)&&ans==-1)
			{
				System.out.println("? "+x2);
				hs.add(x2);
				z=in.readInt();
				if(z==2)
				{
					int bb1=in.readInt();
			   		int bb2=in.readInt();
					ans=x2;
					System.out.println("! "+x2);
				}
				else
		        	{
		        		int bb1=in.readInt();
		        		int bb2=in.readInt();
		        		int bb3=in.readInt();
		        	}
			}
			if(!hs.contains(x3)&&ans==-1)
			{
				System.out.println("? "+x3);
				hs.add(x3);
				z=in.readInt();
				if(z==2)
				{
					int bb1=in.readInt();
			   		int bb2=in.readInt();
					ans=x3;
					System.out.println("! "+x3);
				}
				else
		        	{
		        		int bb1=in.readInt();
		        		int bb2=in.readInt();
		        		int bb3=in.readInt();
		        	}
			}
		}
	}
	static void l6(int u)
	{
		int x1,x2,x3,z,f;
		int ele=ar1.get((3+u));
		hs.add(ele);
		for(int zz:ar[ele])
		{
			if(!hs.contains(zz))
			{
				System.out.println("! "+zz);
			}
		}
	}
	static boolean dfs1(int i)
	{
		 hs.add(i);
		 ar1.add(i);
		 System.out.println("? "+i);
		 boolean f=false;
		 int k=in.readInt();
		 if(k==1)
		 {
			 int bb1=in.readInt();
			 return true;
		 }
		 else if(k==2)
		 {
			 ans=i;
			 int bb1=in.readInt();
		   	 int bb2=in.readInt();
			 return true;
		 }
		 else
		 {
			 int x1=in.readInt();
     		 int x2=in.readInt();
     		 int x3=in.readInt();
     		 ar[i].add(x1);
     		 ar[i].add(x2);
     		 ar[i].add(x3);
     		 if(!hs.contains(x1))
     		 {
     			 dfs1(x1);
     		 }
     		 else if(!hs.contains(x2))
     		 {
     			 dfs1(x2);
     		 }
     		 else
     		 {
     			 dfs1(x3);
     		 }

		 }
		 return f;
	}
	static boolean dfs2(int i)
	{
		 hs.add(i);
		 ar2.add(i);
		 System.out.println("? "+i);
		 boolean f=false;
		 int k=in.readInt();
		 if(k==1)
		 {
			 int bb1=in.readInt();
			 return true;
		 }
		 else if(k==2)
		 {
			 int bb1=in.readInt();
		   	 int bb2=in.readInt();
			 ans=i;
			 return true;
		 }
		 else
		 {
			 int x1=in.readInt();
     		 int x2=in.readInt();
     		 int x3=in.readInt();
     		 ar[i].add(x1);
     		 ar[i].add(x2);
     		 ar[i].add(x3);
     		 if(!hs.contains(x1))
     		 {
     			 dfs2(x1);
     		 }
     		 else if(!hs.contains(x2))
     		 {
     			 dfs2(x2);
     		 }
     		 else
     		 {
     			 dfs2(x3);
     		 }

		 }
		 return f;
	}
    public static void main(String[] args) throws Exception{

    	PrintWriter pw=new PrintWriter(System.out);

    	int t=in.readInt();
        while(t-->0)
        {
    	ans=-1;
        int h=in.readInt();
        for(int i=0;i<200;i++)
        	ar[i]=new ArrayList<Integer>();
        hs=new HashSet<Integer>();
        ar1=new ArrayList<Integer>();
        ar2=new ArrayList<Integer>();
        System.out.println("? 1");
        int k=in.readInt();
        hs.add(1);
        if(k==2)
        {
        	int bb1=in.readInt();
       		int bb2=in.readInt();
        	System.out.println("! 1");
        }
        else if(k==1)
        {
        	l1();
        }
        else
        {
        	int y=1;
        	int x1=in.readInt();
        	int x2=in.readInt();
        	int x3=in.readInt();
        	ar[1].add(x1);
        	ar[1].add(x2);
        	ar[1].add(x3);
        	hs.add(1);
        	dfs1(x1);
        	dfs2(x2);
        	int s1=ar1.size();
        	int s2=ar2.size();
        	if(ans!=-1)
        	{
        		System.out.println("! "+ans);
        	}
        	else
        	{
        		if(s1==s2)
        		{
        			ar1=new ArrayList<Integer>();
        			ar2=new ArrayList<Integer>();
        			int l=s1+1;
        			if(l==2)
        			{
        				int cur=x3;
        				for(int xx:ar[y])
        				{
        					if(!hs.contains(xx))
        					{
        						cur=xx;
        						break;
        					}
        				}
        				dfs1(cur);
        				if(ans!=-1)
        				{
        					System.out.println("! "+ans);
        				}
        				else
        				{
        					if(ar1.size()==3)
        					{
        						l3(1);
        					}
        					else if(ar1.size()==5)
        					{
        						l4(1);
        					}
        					else if(ar1.size()==7)
        					{
        						l5(1);
        					}
        					else if(ar1.size()==9)
        					{
        						l6(1);
        					}

        				}
        			}

        			else if(l==3)
        			{
        				int cur=x3;
        				for(int xx:ar[y])
        				{
        					if(!hs.contains(xx))
        					{
        						cur=xx;
        						break;
        					}
        				}
        				dfs1(cur);
        				if(ans!=-1)
        				{
        					System.out.println("! "+ans);
        				}
        				else
        				{
        					if(ar1.size()==4)
        					{
        						l4(-1);
        					}
        					else if(ar1.size()==6)
        					{
        						l5(-1);
        					}
        					else if(ar1.size()==8)
        					{
        						l6(-1);
        					}
        				}
        			}
        			else if(l==4)
        			{
        				int cur=x3;
        				for(int xx:ar[y])
        				{
        					if(!hs.contains(xx))
        					{
        						cur=xx;
        						break;
        					}
        				}
        				dfs1(cur);
        				if(ans!=-1)
        				{
        					System.out.println("! "+ans);
        				}
        				else
        				{
        					if(ar1.size()==5)
        					{
        						l5(-2);
        					}
        					else if(ar1.size()==7)
        					{
        						l6(-2);
        					}

        				}
        			}
        			else if(l==5)
        			{
        				int cur=x3;
        				for(int xx:ar[y])
        				{
        					if(!hs.contains(xx))
        					{
        						cur=xx;
        						break;
        					}
        				}
        				dfs1(cur);
        				if(ans!=-1)
        				{
        					System.out.println("! "+ans);
        				}
        				else
        				{
        					for(int xx:ar[cur])
            				{
            					if(!hs.contains(xx))
            					{
            						cur=xx;
            						ans=xx;
            						int bb1=in.readInt();
	           		        		int bb2=in.readInt();
	           		        		System.out.println("! "+ans);
            						break;
            					}
            				}
        				}
        			}
        			else if(l==6)
        			{
        				System.out.println("! "+x3);
        			}
        		}
        		else
        		{
        			if(s1<s2)
        			{
        				swap();
        			}
        			s1=ar1.size();
        			s2=ar2.size();
        			int l=s2+1;
        			if(l==2)
        			{
        				if(ar1.size()==3)
    					{
    						l3(0);
    					}
    					else if(ar1.size()==5)
    					{
    						l4(0);
    					}
    					else if(ar1.size()==7)
    					{
    						l5(0);
    					}
    					else if(ar1.size()==9)
    					{
    						l6(0);
    					}
        			}
        			else if(l==3)
        			{
        				if(ar1.size()==4)
					{
						l4(-1);
					}
					else if(ar1.size()==6)
					{
						l5(-1);
					}
					else if(ar1.size()==8)
					{
						l6(-1);
					}
        			}
        			else if(l==4)
        			{
        				if(ar1.size()==5)
    					{
    						l5(-2);
    					}
    					else if(ar1.size()==7)
    					{
    						l6(-2);
    					}
        			}
        			else if(l==5)
        			{
        				l6(-3);
        			}
        		}

        	}
        }

    	}

    	pw.close();
    }

static  class InputReader
{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read(buf);
            } catch (IOException e)
            {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do
        {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    public String readLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    public double readDouble() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        double res = 0;
        while (!isSpaceChar(c) && c != '.') {
            if (c == 'e' || c == 'E')
                return res * Math.pow(10, readInt());
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpaceChar(c)) {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                m /= 10;
                res += (c - '0') * m;
                c = read();
            }
        }
        return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
    public boolean isSpaceChar(int c)
    {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next()
    {
        return readString();
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
    public boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }
}

}