import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            GCowAndExercise solver = new GCowAndExercise();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class GCowAndExercise {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();
            int[][] edges = new int[m][3];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < 3; j++) {
                    edges[i][j] = in.readInt();
                }
            }
            List<IntegerCostFlowEdge>[] g = IntegerFlow.createCostFlow(n);
            for (int[] e : edges) {
                int u = e[0] - 1;
                int v = e[1] - 1;
                int w = e[2];
                IntegerFlow.addCostEdge(g, u, v, 1, w);
            }

            List<LinearFunction> list = new ArrayList<>();
            IntegerAugmentCallback callback = new IntegerAugmentCallback() {
                int sumFlow = 0;
                int sumCost = 0;

                public void callback(int flow, int pathCost) {
                    sumFlow += flow;
                    sumCost += flow * pathCost;

                    if (!list.isEmpty() && list.get(list.size() - 1).l == pathCost) {
                        list.remove(list.size() - 1);
                    }
                    LinearFunction func = new LinearFunction(pathCost, sumFlow, -sumCost);
                    list.add(func);
                }
            };
            IntegerDijkstraV2MinimumCostFlow mcf = new IntegerDijkstraV2MinimumCostFlow(n);
            mcf.setCallback(callback);
            mcf.apply(g, 0, n - 1, (int) 1e8);
            LinearFunction[] fs = list.toArray(new LinearFunction[0]);

            int q = in.readInt();
            Query[] qs = new Query[q];
            for (int i = 0; i < q; i++) {
                qs[i] = new Query();
                qs[i].x = in.readInt();
            }

            Query[] sortedQs = qs.clone();
            Arrays.sort(sortedQs, (a, b) -> Integer.compare(a.x, b.x));
            int cur = -1;
            for (Query query : sortedQs) {
                while (cur + 1 < fs.length && fs[cur + 1].getL() <= query.x) {
                    cur++;
                }
                query.ans = fs[cur].getX(query.x);
            }

            for (Query query : qs) {
                out.println(query.ans);
            }
        }

    }

    static class Query {
        int x;
        double ans;

    }

    static interface IntegerDeque extends IntegerStack {
        int removeFirst();

    }

    static class IntegerDijkstraV2MinimumCostFlow implements IntegerMinimumCostFlow {
        private int m;
        private int[] lastDist;
        private int[] curDist;
        private IntegerCostFlowEdge[] prev;
        private boolean[] inq;
        private IntegerDeque dq;
        private static final int INF = Integer.MAX_VALUE / 4;
        private List<IntegerCostFlowEdge>[] g;
        private IntegerAugmentCallback callback = IntegerAugmentCallback.NIL;

        public void setCallback(IntegerAugmentCallback callback) {
            this.callback = callback;
        }

        public IntegerDijkstraV2MinimumCostFlow(int m) {
            this.m = m - 1;
            lastDist = new int[m];
            curDist = new int[m];
            prev = new IntegerCostFlowEdge[m];
            inq = new boolean[m];
            dq = new IntegerDequeImpl(m);
        }

        private void bf(int s) {
            int n = g.length;
            dq.clear();
            for (int i = 0; i < n; i++) {
                lastDist[i] = INF;
                inq[i] = false;
            }
            lastDist[s] = 0;
            inq[s] = true;
            dq.addLast(s);
            while (!dq.isEmpty()) {
                int head = dq.removeFirst();
                inq[head] = false;
                for (IntegerCostFlowEdge e : g[head]) {
                    if (DigitUtils.equal(e.rev.flow, 0) || lastDist[e.to] <= lastDist[head] + e.cost) {
                        continue;
                    }
                    lastDist[e.to] = lastDist[head] + e.cost;
                    if (!inq[e.to]) {
                        inq[e.to] = true;
                        dq.addLast(e.to);
                    }
                }
            }
        }

        private void dijkstra(int s) {
            int n = g.length;
            for (int i = 0; i < n; i++) {
                curDist[i] = INF;
                prev[i] = null;
                inq[i] = false;
            }
            curDist[s] = 0;

            for (int i = 0; i < n; i++) {
                int head = -1;
                for (int j = 0; j < n; j++) {
                    if (!inq[j] && (head == -1 || curDist[j] < curDist[head])) {
                        head = j;
                    }
                }
                if (curDist[head] >= INF) {
                    break;
                }
                inq[head] = true;
                for (IntegerCostFlowEdge e : g[head]) {
                    int dist;
                    if (e.rev.flow == 0 || curDist[e.to] <= (dist = curDist[head] + e.cost - lastDist[e.to] + lastDist[head])) {
                        continue;
                    }
                    prev[e.to] = e.rev;
                    curDist[e.to] = dist;
                }
            }

            for (int i = 0; i < n; i++) {
                lastDist[i] = Math.min(curDist[i] + lastDist[i], INF);
            }
        }

        public int[] apply(List<IntegerCostFlowEdge>[] net, int s, int t, int send) {
            this.g = net;
            bf(s);
            int flow = 0;
            int cost = 0;
            while (flow < send) {
                dijkstra(s);
                if (prev[t] == null) {
                    break;
                }
                int remain = send - flow;
                for (IntegerCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    remain = Math.min(remain, trace.flow);
                }
                int sumOfCost = 0;
                for (IntegerCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    sumOfCost -= trace.cost;
                    IntegerFlow.send(trace, -remain);
                }
                cost += sumOfCost * -remain;
                flow += remain;
                callback.callback(remain, sumOfCost);
            }
            return new int[]{flow, cost};
        }

    }

    static interface IntegerStack {
        void addLast(int x);

        boolean isEmpty();

        void clear();

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static interface IntegerMinimumCostFlow {
    }

    static class IntegerCostFlowEdge extends IntegerFlowEdge<IntegerCostFlowEdge> {
        public int cost;

        public IntegerCostFlowEdge(int to, int flow, boolean real, int cost) {
            super(to, flow, real);
            this.cost = cost;
        }

    }

    static class IntegerDequeImpl implements IntegerDeque {
        private int[] data;
        private int bpos;
        private int epos;
        private static final int[] EMPTY = new int[0];
        private int n;

        public IntegerDequeImpl(int cap) {
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
            bpos = 0;
            epos = 0;
            n = cap;
        }

        private void expandSpace(int len) {
            while (n < len) {
                n = Math.max(n + 10, n * 2);
            }
            int[] newData = new int[n];
            if (bpos <= epos) {
                if (bpos < epos) {
                    System.arraycopy(data, bpos, newData, 0, epos - bpos);
                }
            } else {
                System.arraycopy(data, bpos, newData, 0, data.length - bpos);
                System.arraycopy(data, 0, newData, data.length - bpos, epos);
            }
            epos = size();
            bpos = 0;
            data = newData;
        }

        public IntegerIterator iterator() {
            return new IntegerIterator() {
                int index = bpos;

                public boolean hasNext() {
                    return index != epos;
                }

                public int next() {
                    int ans = data[index];
                    index = IntegerDequeImpl.this.next(index);
                    return ans;
                }
            };
        }

        public int removeFirst() {
            int ans = data[bpos];
            bpos = next(bpos);
            return ans;
        }

        public void addLast(int x) {
            ensureMore();
            data[epos] = x;
            epos = next(epos);
        }

        public void clear() {
            bpos = epos = 0;
        }

        private int next(int x) {
            return x + 1 >= n ? 0 : x + 1;
        }

        private void ensureMore() {
            if (next(epos) == bpos) {
                expandSpace(n + 1);
            }
        }

        public int size() {
            int ans = epos - bpos;
            if (ans < 0) {
                ans += data.length;
            }
            return ans;
        }

        public boolean isEmpty() {
            return bpos == epos;
        }

        public String toString() {
            StringBuilder builder = new StringBuilder();
            for (IntegerIterator iterator = iterator(); iterator.hasNext(); ) {
                builder.append(iterator.next()).append(' ');
            }
            return builder.toString();
        }

    }

    static interface IntegerAugmentCallback {
        public static IntegerAugmentCallback NIL = (a, b) -> {
        };

        public void callback(int flow, int pathCost);

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static boolean equal(int a, int b) {
            return a == b;
        }

    }

    static class DirectedEdge {
        public int to;

        public DirectedEdge(int to) {
            this.to = to;
        }

        public String toString() {
            return "->" + to;
        }

    }

    static class IntegerFlow {
        public static <T extends IntegerFlowEdge> void send(T edge, int flow) {
            edge.flow += flow;
            edge.rev.flow -= flow;
        }

        public static IntegerCostFlowEdge addCostEdge(List<IntegerCostFlowEdge>[] g, int s, int t, int cap, int cost) {
            IntegerCostFlowEdge real = new IntegerCostFlowEdge(t, 0, true, cost);
            IntegerCostFlowEdge virtual = new IntegerCostFlowEdge(s, cap, false, -cost);
            real.rev = virtual;
            virtual.rev = real;
            g[s].add(real);
            g[t].add(virtual);
            return real;
        }

        public static List<IntegerCostFlowEdge>[] createCostFlow(int n) {
            return createGraph(n);
        }

        private static List[] createGraph(int n) {
            return IntStream.range(0, n).mapToObj(i -> new ArrayList<>()).toArray(i -> new List[i]);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(double c) {
            cache.append(new BigDecimal(c).toPlainString());
            return this;
        }

        public FastOutput println(double c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class LinearFunction {
        int l;
        long a;
        long b;

        public LinearFunction(int l, long a, long b) {
            this.l = l;
            this.a = a;
            this.b = b;
        }

        long getL() {
            return a * l + b;
        }

        double getX(double y) {
            return (y - b) / a;
        }

    }

    static class IntegerFlowEdge<T extends IntegerFlowEdge<T>> extends DirectedEdge {
        public int flow;
        public boolean real;
        public T rev;

        public IntegerFlowEdge(int to, int flow, boolean real) {
            super(to);
            this.flow = flow;
            this.real = real;
        }

        public String toString() {
            return rev.to + "-[" + flow + "/" + (flow + rev.flow) + "]->" + to;
        }

    }

    static interface IntegerIterator {
        boolean hasNext();

        int next();

    }
}


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

public class HappyNumbers implements Runnable {
    private void solve() throws IOException {
        /*for (long l = 1; l <= 1000; ++l) {
            System.out.println(l);
            for (long a = 1; a <= 1000; ++a) {
                if (doit(a, l) != doit2(a, l))
                    throw new RuntimeException(a + " " + l);
            }
        }*/
        long a = nextLong();
        long l = nextLong();
        System.out.println(doit(a, l));
    }

    /*private long doit2(long a, long l) {
        for (long b = a + 1;; ++b) {
            boolean ok = true;
            for (int i = 0; i < l; ++i)
                if (countLucky(a + i) != countLucky(b + i)) {
                    ok = false;
                    break;
                }
            if (ok)
                return b;
        }
    }*/

    private long doit(long a, long l) {
        if (l >= 10) {
            long first = a;
            long last = a + l - 1;
            return doit(first / 10, last / 10 - first / 10 + 1) * 10 + first % 10;
        } else {
            int[] cnts = new int[(int) l];
            for (int i = 0; i < l; ++i)
                cnts[i] = countLucky(a + i);
            return doitFrom(cnts, a + 1);
        }
    }

    private long doitFrom(int[] cnts, long min) {
        if (cnts.length == 1) {
            return doitOne(cnts[0], min);
        } else if (cnts.length == 2 && min <= 1) {
            return doitTwoSimple(cnts[0], cnts[1], min);
        }
        long res = Long.MAX_VALUE;
        for (int lastDigit = 0; lastDigit < 10; ++lastDigit) {
            int max = lastDigit + cnts.length - 1;
            int[] ncnts = new int[max / 10 + 1];
            Arrays.fill(ncnts, -1);
            boolean ok = true;
            for (int i = 0; i < cnts.length; ++i) {
                int cur = lastDigit + i;
                int need = cnts[i];
                if (cur % 10 == 4 || cur % 10 == 7)
                    --need;
                if (need < 0) {
                    ok = false;
                    break;
                }
                if (ncnts[cur / 10] < 0 || ncnts[cur / 10] == need) {
                    ncnts[cur / 10] = need;
                } else {
                    ok = false;
                    break;
                }
            }
            if (!ok) continue;
            long newMin = min / 10 - 3;
            while (newMin * 10 + lastDigit < min)
                ++newMin;
            long tmp = doitFrom(ncnts, newMin) * 10 + lastDigit;
            res = Math.min(res, tmp);
        }
        return res;
    }

    private long doitTwoSimple(int cntFirst, int cntSecond, long min) {
        if (cntFirst == 0 && cntSecond == 0)
            return min;
        if (cntFirst == cntSecond) {
            long res = 0;
            for (int i = 0; i < cntFirst; ++i)
                res = res * 10 + 4;
            return res * 10;
        } else if (cntFirst == cntSecond + 1) {
            long res = 0;
            for (int i = 0; i < cntFirst; ++i)
                res = res * 10 + 4;
            return res;
        } else if (cntFirst + 1 == cntSecond) {
            long res = 0;
            for (int i = 0; i < cntSecond; ++i)
                res = res * 10 + 4;
            return res - 1;
        } else {
            return Long.MAX_VALUE;
        }
    }

    private long doitOne(int cnt, long min) {
        long p10 = 1;
        int pow = 0;
        while (p10 <= min) {
            p10 *= 10;
            ++pow;
        }
        p10 *= 100;
        pow += 2;
        while (pow < cnt + 2) {
            p10 *= 10;
            ++pow;
        }
        long res = 0;
        while (true) {
            for (int curDigit = 0; curDigit < 10; ++curDigit) {
                int curCnt = 0;
                if (curDigit == 4 || curDigit == 7) curCnt = 1;
                if (possible(res, p10, pow, cnt - curCnt, min)) {
                    cnt -= curCnt;
                    break;
                }
                res += p10;
                if (curDigit == 9)
                    throw new RuntimeException();
            }
            if (p10 == 1) break;
            p10 /= 10;
            --pow;
        }
        return res;
    }

    private boolean possible(long res, long p10, int pow, int needLucky, long min) {
        if (needLucky > pow || needLucky < 0)
            return false;
        long cur = 0;
        for (int i = 0; i < pow - needLucky; ++i)
            cur = cur * 10 + 9;
        for (int i = 0; i < needLucky; ++i)
            cur = cur * 10 + 7;
        return res + cur >= min;
    }

    private int countLucky(long x) {
        int res = 0;
        while (x > 0) {
            long dig = x % 10;
            x /= 10;
            if (dig == 4 || dig == 7) ++res;
        }
        return res;
    }

    public static void main(String[] args) {
        new HappyNumbers().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.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(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


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

public class C {

	static final int P = 1_000_000_007;

	static boolean nextPermutation(int[] a) {
		int n = a.length;
		int ptr = n - 1;
		while (ptr > 0 && a[ptr - 1] >= a[ptr]) {
			ptr--;
		}

		for (int i = ptr, j = n - 1; i < j; i++, j--) {
			int tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}

		if (ptr == 0) {
			return false;
		}

		for (int i = ptr;; i++) {
			if (a[ptr - 1] < a[i]) {
				int tmp = a[ptr - 1];
				a[ptr - 1] = a[i];
				a[i] = tmp;
				return true;
			}
		}
	}

	int slow(int n, int k) {
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}
		int ans = 0;
		do {
			int m = 0;
			int offset = 0;
			for (int i = 0; i < n; ++i)
				if (m < p[i]) {
					m = p[i];
					offset = 0;
				} else {
					offset = offset + 1;
					if (offset == k)
						break;
				}
			ans += m == n - 1 ? 1 : 0;
		} while (nextPermutation(p));
		return ans;
	}

	void submit() {
		int n = nextInt();
		int k = nextInt();
		int[] a = new int[n + 1];
		a[0] = 1;
		for (int i = 1; i <= k && i <= n; i++) {
			a[i] = (int) ((long) (i + 1) * a[i - 1] % P);
		}

		if (n <= k) {
			out.println(0);
			return;
		}

		int mult = a[k - 1];

		for (int i = k + 1; i <= n; i++) {
			a[i] = (int) ((long) (i + 1) * a[i - 1] % P);
			a[i] -= (int) ((long) mult * a[i - k - 1] % P);
			if (a[i] < 0) {
				a[i] += P;
			}

			mult = (int) ((long) mult * i % P * inv(i - k) % P);
		}

		int fact = 1;
		for (int i = 1; i <= n; i++) {
			fact = (int) ((long) fact * i % P);
		}

		n--;

		fact -= a[n];
		if (fact < 0) {
			fact += P;
		}

		out.println(fact);
	}

	int inv(int x) {
		return x == 1 ? 1 : (P - (int) ((long) (P / x) * inv(P % x) % P));
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {
		int[] a = new int[11];
		a[0] = 1;
		a[1] = 2;
		a[2] = 6;
		for (int i = 3; i < a.length; i++) {
			a[i] = (i + 1) * a[i - 1] - (i - 1) * (i - 2) * a[i - 3];
		}
		System.err.println(Arrays.toString(a));

		a[0] = 1;
		a[1] = 2;
		a[2] = 6;
		a[3] = 24;
		for (int i = 4; i < a.length; i++) {
			a[i] = (i + 1) * a[i - 1] - (i - 1) * (i - 2) * (i - 3) * a[i - 4];
		}
		System.err.println(Arrays.toString(a));

		for (int n = 1; n <= 11; n++) {
			System.err.println(slow(n, 2) + " " + a[n]);
		}
	}

	C() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new C();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

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

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

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


import java.util.*;

/**
 *
 * @author greggy
 */
public class IQTest176 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[][] grid = new char[4][4];
        boolean ans = false;

        for (int i = 0; i < 4; i++) {
            String color = in.nextLine();
            grid[i] = color.toCharArray();
        }

        for (int i = 1; i < 4; i++) {
            for (int j = 1; j < 4; j++) {
                if ((grid[i - 1][j - 1] == grid[i - 1][j] && grid[i - 1][j - 1] == grid[i][j - 1]) || (grid[i][j] == grid[i - 1][j - 1] && grid[i - 1][j - 1] == grid[i][j - 1]) || (grid[i][j] == grid[i - 1][j] && grid[i - 1][j] == grid[i][j - 1])) {
                    ans = true;
                    break;
                }
            }
        }
        if (ans == true) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

}


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

	public class CODEFORCES {
		private InputStream is;
		private PrintWriter out;
		int time = 0, val[][], dp[][], DP[], start[], end[], dist[],  black[], MOD = (int)(1e9+7), arr[], weight[][], x[], y[], parent[];
		int MAX = 800000, N, K;
		long red[];
		ArrayList<Integer>[] amp;
		//boolean b[], boo[][];
		Pair prr[];
		HashSet<Integer> hs = new HashSet<>();
		long Dp[][][][] = new long[110][110][12][12];
		void soln() {
			is = System.in;
			out = new PrintWriter(System.out);
			long s = System.currentTimeMillis();
			solve();
			//out.close();
			out.flush();
			//tr(System.currentTimeMillis() - s + "ms");
		}
		public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
			public void run() {
				try {

			//new CODEFORCES().soln();
			} catch (Exception e) {
					System.out.println(e);
				}
			}
		}, "1", 1 << 26).start();
			new CODEFORCES().soln();
		}
		int a,b;
		void solve() {
			int n=ni(),k=ni(),i,c=0;
			for(i=1;i<=n;i++){
				int x=ni()+c;
				k-=Math.min(x, 8);
				c=x-Math.min(x, 8);
				if(k<=0)
					break;
			}
			if(i<=n)
				System.out.println(i);
			else
				System.out.println(-1);
		}
		boolean check(int ans){
			while(ans>0){
				int c = ans%10;
				if(!(c==a||c==b)) return false;
				ans/=10;
			}
			return true;
		}
		long npr(long[] power, int n,int r){
			if(r>n) return 0;
			return (((power[n]*power(power[r], MOD-2, MOD))%MOD)*power(power[n-r], MOD-2, MOD))%MOD;
		}

		class Pair implements Comparable<Pair>{
			int u, v, i;
			Pair(int u, int v){
				this.u = u;
				this.v = v;
			}
			Pair(int u, int v, int i){
				this.u = u;
				this.v = v;
				this.i = i;
			}
			public int hashCode() {
				return Objects.hash();
			}
			/*public boolean equals(Object o) {
				Pair other = (Pair) o;
				return ((u == other.u && v == other.v) || (v == other.u && u == other.v));
			}*/
			public int compareTo(Pair other) {
				//return Integer.compare(val, other.val);
				return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(v,other.v));
			}
			public String toString(){
				return this.u +" " + this.v;
			}
		}
		int max(int a, int b){
			if(a>b) return a;
			return b;
		}

		void buildGraph(int n){
			for(int i = 0; i<n ;i++){
				int x1 = ni() -1, y1 = ni()-1;
				amp[x1].add(y1);
				amp[y1].add(x1);
				x[i] = x1; y[i] = y1;
			}
		}
		long modInverse(long a, long mOD2){
	        return  power(a, mOD2-2, mOD2);
		}
		long power(long x, long y, long m)
		{
			if (y == 0)
	    return 1;
		long p = power(x, y/2, m) % m;
		p = (p * p) % m;

		return (y%2 == 0)? p : (x * p) % m;
		}
		public long gcd(long a, long b){
			if(b==0) return a;
			return gcd(b,a%b);
		}
		static class ST1{
			int arr[], st[], size;
			ST1(int a[]){
				arr = a.clone();
				size = 10*arr.length;
				st = new int[size];
				build(0,arr.length-1,1);
			}
			void build(int ss, int se, int si){
				if(ss==se){
					st[si] = arr[ss];
					return;
				}
				int mid = (ss+se)/2;
				int val = 2*si;
				build(ss,mid,val); build(mid+1,se,val+1);
				st[si] = Math.min(st[val], st[val+1]);
			}
			int get(int ss, int se, int l, int r, int si){
				if(l>se || r<ss || l>r) return Integer.MAX_VALUE;
				if(l<=ss && r>=se) return st[si];
				int mid = (ss+se)/2;
				int val = 2*si;
				return Math.min(get(ss,mid,l,r,val), get(mid+1,se,l,r,val+1));
			}
		}
		static class ST{
			int arr[],lazy[],n;
			ST(int a){
				n = a;
				arr = new int[10*n];
				lazy = new int[10*n];
			}
			void up(int l,int r,int val){
				update(0,n-1,0,l,r,val);
			}
			void update(int l,int r,int c,int x,int y,int val){
				if(lazy[c]!=0){
					lazy[2*c+1]+=lazy[c];
					lazy[2*c+2]+=lazy[c];
					if(l==r)
						arr[c]+=lazy[c];
					lazy[c] = 0;
				}
				if(l>r||x>y||l>y||x>r)
					return;
				if(x<=l&&y>=r){
					lazy[c]+=val;
					return ;
				}
				int mid = l+r>>1;
				update(l,mid,2*c+1,x,y,val);
				update(mid+1,r,2*c+2,x,y,val);
				arr[c] = Math.max(arr[2*c+1], arr[2*c+2]);
			}
			int an(int ind){
				return ans(0,n-1,0,ind);
			}
			int ans(int l,int r,int c,int ind){
				if(lazy[c]!=0){
					lazy[2*c+1]+=lazy[c];
					lazy[2*c+2]+=lazy[c];
					if(l==r)
						arr[c]+=lazy[c];
					lazy[c] = 0;
				}
				if(l==r)
					return arr[c];
				int mid = l+r>>1;
				if(mid>=ind)
					return ans(l,mid,2*c+1,ind);
				return ans(mid+1,r,2*c+2,ind);
			}
		}
		public static int[] shuffle(int[] a, Random gen){
			for(int i = 0, n = a.length;i < n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int d = a[i];
				a[i] = a[ind];
				a[ind] = d;
			}
		return a;
		}
		long power(long x, long y, int mod){
			long ans = 1;
			while(y>0){
				if(y%2==0){
					x = (x*x)%mod;
					y/=2;
				}
				else{
					ans = (x*ans)%mod;
					y--;
				}
			}
			return ans;
		}

		// To Get Input
		// Some Buffer Methods
		private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		private double nd() {
			return Double.parseDouble(ns());
		}

		private char nc() {
			return (char) skip();
		}
		private String ns() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
										// ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = ns(m);
			return map;
		}

		private int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = ni();
			return a;
		}

		private int ni() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

		private void tr(Object... o) {
			if (!oj)
				System.out.println(Arrays.deepToString(o));
		}
	}


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

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

class TaskSolver {
    private InputReader in;
    private PrintWriter out;

    public TaskSolver(InputReader inputReader, PrintWriter printWriter) {
        in = inputReader;
        out = printWriter;
    }

    public void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        int m = in.nextInt();
        int r0 = in.nextInt();
        int[] r = new int[ (int) 1e+6];
        int[] check = new int[ (int) 1e+6];
        Arrays.fill(check, -1);
        r[0] = (a * r0 + b) % m;
        check[r[0]] = 0;
        int res = 0;
        for (int i = 1; ; i++) {
            r[i] = (a * r[i - 1] + b) % m;
            if (check[r[i]] == -1) {
                check[r[i]] = i;
            } else {
                res = i - check[r[i]];
                break;
            }
        }
        out.print(res);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = null;
    }

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

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


import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Round139_B {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int s = in.nextInt();
		int k = in.nextInt();
		int MAX = 50;
		long[] a = new long[MAX];
		int maxl = Math.min(MAX, k);
		a[0] = 1;
		long sum = 1;
		boolean done = true;
		int lasto = 0;
		for (int i = 1; i < maxl; i++) {
			a[i] = sum;
			sum += sum;
			if (done && a[i] < 1000000100)
				lasto = i;
			else
				done = false;
		}

		for (int i = maxl; i < MAX; i++) {
			a[i] = 2 * a[i - 1] - (((i - (k + 1)) > -1) ? a[i - (k + 1)] : 0);
			if (done && a[i] < 1000000100)
				lasto = i;
			else
				done = false;
		}

		StringBuffer ans = new StringBuffer("");
		int tmp = s;
		int count = lasto;
		ArrayList<Long> fin = null;

		while (count > -1) {
			fin = new ArrayList<Long>();
			HashSet<Integer> hash = new HashSet<Integer>();
			tmp = s;
			for (int j = count; j > -1; j--) {
				if (a[j] <= tmp) {

					if (hash.contains((int) a[j]))
						continue;
					tmp -= a[j];
					fin.add(a[j]);
					hash.add((int) a[j]);
				}
			}
			if (tmp == 0)
				break;
			count--;
		}
		if (fin.size() == 1)
			fin.add((long)0);
		int m = fin.size();
		System.out.println(m);
		if (m != 0)
			ans.append(fin.get(0));
		for (int i = 1; i < m; i++)
			ans.append(" " + fin.get(i));
		System.out.println(ans.toString());
	}
}


/*Author: Satyajeet Singh, Delhi Technological University*/
    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.lang.*;
    import java.math.*;

public class Main{
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static long factorial[],invFactorial[];
    static ArrayList<Pair> graph[];
    static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
/****************************************Solutions Begins***************************************/
    static void fact(int n){
        factorial=new long[n+1];
        invFactorial=new long [n+1];
        factorial[0]=1l;
        invFactorial[0]=1l;
        for(int i=1;i<=n;i++){
            factorial[i]=(factorial[i-1]*i)%mod;
            invFactorial[i]=modulo(factorial[i],mod-2,mod);
        }
    }
/*******************************************ncr*********************************************************/
    static long ncr(int n,int k){
        long aa=invFactorial[n-k];
        long bb=invFactorial[k];
        long cc=factorial[n];
        long ans=(aa*cc)%mod;
        ans=(ans*bb)%mod;
        return ans;
    }
    public static void main(String[] args) throws Exception{
        String st[]=nl();
        int n=pi(st[0]);
        long k=pl(st[1]);
        fact(100000);
        long ans=0;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                long sgn=1;
                if((i+j)%2==1){
                    sgn=-1;
                }
                long yy=(ncr(n,i)*ncr(n,j))%mod;
                long aa=(modulo(k,n*n-n*(i+j)+i*j,mod)*modulo(k-1,n*(i+j)-i*j,mod))%mod;
                yy=(yy*aa)%mod;
                yy=yy*sgn;
                ans+=yy;
                ans%=mod;
                ans+=mod;
                ans%=mod;
            }
        }
        out.println(ans);
/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins************************************************/
    static String[] nl() throws Exception{
        return br.readLine().split(" ");
    }
    static String[] nls() throws Exception{
        return br.readLine().split("");
    }
    static int pi(String str) {
        return Integer.parseInt(str);
    }
    static long pl(String str){
        return Long.parseLong(str);
    }
    static double pd(String str){
        return Double.parseDouble(str);
    }
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.000000000000000000000");
        out.print(ft.format(d));
    }
/**************************************Bit Manipulation**************************************************/
    static void printMask(long mask){
        System.out.println(Long.toBinaryString(mask));
    }
    static int countBit(long mask){
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new ArrayList[n];
        for(int i=0;i<n;i++){
            graph[i]=new ArrayList<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(new Pair(b,1));
    }
    static void addEdge(int a,int b,int c){
        graph[a].add(new Pair(b,c));
    }
/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u)
            return p1.u-p2.u;
            else
            return p1.v-p2.v;
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/******************************************Long Pair*******************************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            long a=p1.u*p2.v;
            long b=p2.u*p1.v;
            if(a>b){
                return -1;
            }
            else if(a<b){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pairl> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pairl other = (Pairl) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pairl other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        if(!oj)
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a%c;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}


import java.util.Scanner;

public class Suits {

	public static void main(String[] args) {
		Scanner scan= new Scanner(System.in);
		int a =scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int d=scan.nextInt();
		int e=scan.nextInt();
		int f=scan.nextInt();
		if(f>e)
		{
			int n=Math.min(b,c);
			int m=Math.min(n, d);
			d=d-m;
			d=Math.min(d, a);
			System.out.println(m*f+d*e);
		}
		else
		{
			int n=Math.min(a, d);
			int m=Math.min(b, c);
			d=d-n;
			d=Math.min(d,m);
			System.out.println(n*e+d*f);

		}

	}

}


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

public class D implements Runnable {

	static class BitSet {
		static final int MOD = 63;
		long [] a;

		BitSet(int n) {
			a = new long[(n >> 6) + 1];
		}

		BitSet(long [] a) {
			this.a = a;
		}

		void set(int bit) {
			int i = bit >> 6;
			a[i] |= 1L << (bit & MOD);
		}

		boolean isSet(int bit) {
			return (a[bit >> 6] & (1L << (bit & MOD))) != 0;
		}

		boolean isEmpty() {
			for (int i = 0; i < a.length; i++) {
				if (a[i] != 0) {
					return false;
				}
			}
			return true;
		}

		int size() {
			int ret = 0;
			for (int i = 0; i < a.length; i++) {
				ret += Long.bitCount(a[i]);
			}
			return ret;
		}

		public BitSet clone() {
			long [] na = new long[a.length];
			System.arraycopy(a, 0, na, 0, a.length);
			return new BitSet(na);
		}

		static long [] tmp = new long[3];

		void shiftLeft(long [] a) {
			for (int i = 0; i < a.length; i++) {
				tmp[i] = a[i] >>> 1;
				if (i < a.length - 1) {
					tmp[i] |= (a[i + 1] & 1) << 63;
				}
			}
		}

		void shiftRight(long [] a) {
			tmp[0] = tmp[1] = tmp[2] = 0;
			for (int i = 0; i < a.length; i++) {
				tmp[i] |= a[i] << 1;
				if (i < a.length - 1) {
					tmp[i + 1] |= (a[i] & (1L << MOD)) >>> MOD;
				}
			}
		}

		void moveRight(long [] row, long [] notL) {
			shiftRight(a);
			for (int i = 0; i < a.length; i++) {
				a[i] = (tmp[i] & row[i]) | (a[i] & notL[i]);
			}
		}

		void moveLeft(long [] row, long [] notR) {
			shiftLeft(a);
			for (int i = 0; i < a.length; i++) {
				a[i] = (tmp[i] & row[i]) | (a[i] & notR[i]);
			}
		}

		void moveUp(long [] row, long [] weLow, long [] notUp) {
			for (int i = 0; i < a.length; i++) {
				a[i] = (row[i] & weLow[i]) | (a[i] & notUp[i]);
			}
		}

		void moveDown(long [] row, long [] weUp, long [] notLow) {
			for (int i = 0; i < a.length; i++) {
				a[i] = (row[i] & weUp[i]) | (a[i] & notLow[i]);
			}
		}
	}

	int exitX, exitY;

	void solve() throws Exception {
		int n = nextInt(), m = nextInt(), k = nextInt();
		BitSet [][] row = new BitSet[2][n];
		BitSet [][] rowL = new BitSet[2][n];
		BitSet [][] rowR = new BitSet[2][n];
		for (int i = 0; i < n; i++) {
			for (int q = 0; q < 2; q++) {
				row[q][i] = new BitSet(m);
				rowL[q][i] = new BitSet(m);
				rowR[q][i] = new BitSet(m);
			}
			char [] b = nextToken().toCharArray();
			for (int j = 0; j < m; j++) {
				int q = b[j] == '#' ? 1 : 0;
				row[q][i].set(j);
				if (j < m - 1) rowR[q][i].set(j + 1);
				if (j > 0) rowL[q][i].set(j - 1);
				if (b[j] == 'E') {
					exitX = j;
					exitY = i;
				}
			}
		}

		BitSet [] we = new BitSet[n];
		for (int i = 0; i < n; i++) {
			we[i] = (BitSet)row[0][i].clone();
		}

		char [] seq = nextToken().toCharArray();
		for (int step = 0; step <= seq.length; step++) {
			boolean done = true;
			for (int i = 0; i < n; i++) {
    				if (i != exitY) {
    					if (!we[i].isEmpty()) {
    						done = false;
    						break;
    					}
    				} else {
    					if (!we[i].isSet(exitX) || !(we[i].size() == 1)) {
    						done = false;
    						break;
    					}
    				}
    			}
			if (done) {
				out.println(step);
				return;
			}

			if (step == seq.length) {
				out.println(-1);
				return;
			}

			char c = seq[step];
     			if (c == 'R') {
     				for (int i = 0; i < n; i++) {
     					we[i].moveRight(row[0][i].a, rowL[1][i].a);
     				}
     			}
     			if (c == 'L') {
     				for (int i = 0; i < n; i++) {
     					we[i].moveLeft(row[0][i].a, rowR[1][i].a);
     				}
     			}
     			if (c == 'U') {
     				for (int i = 1; i < n - 1; i++) {
     					we[i].moveUp(row[0][i].a, we[i + 1].a, row[1][i - 1].a);
     				}
     			}
     			if (c == 'D') {
     				for (int i = n - 2; i > 0; i--) {
     					we[i].moveDown(row[0][i].a, we[i - 1].a, row[1][i + 1].a);
     				}
     			}
		}
	}

	public static void main(String[] args) {
		new Thread(new D()).start();
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sTime();
			solve();
			debug("Time consumed: " + gTime());

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	StringTokenizer tokenizer = new StringTokenizer("");
	BufferedReader in;
	PrintWriter out;
	long time;

	void sTime() {
		time = System.currentTimeMillis();
	}

	long gTime() {
		return System.currentTimeMillis() - time;
	}

	void gMemory() {
		debug("Memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + " kb");
	}

	public void debug(Object o) {
		System.err.println(o);
	}

	boolean seekForToken() {
		while (!tokenizer.hasMoreTokens()) {
			String s = null;
			try {
				s = in.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (s == null)
				return false;
			tokenizer = new StringTokenizer(s);
		}
		return true;
	}

	String nextToken() {
		return seekForToken() ? tokenizer.nextToken() : null;
	}

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

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

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

	BigInteger nextBig() {
		return new BigInteger(nextToken());
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		final int MOD = (int) (1e9 + 7);

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			long n = in.nextLong();
			int k = in.nextInt();
			long ans = 1;
			int[] inv = new int[100];
			for (int i = 1; i < inv.length; i++) {
				inv[i] = BigInteger.valueOf(i).modInverse(BigInteger.valueOf(MOD)).intValue();
			}
			for (Factor f : factorize(n)) {
				long p = f.p;
				int s = f.s;
				int[] d = new int[s + 1];
				int[] nd = new int[s + 1];
				d[s] = 1;
				for (int step = 0; step < k; step++) {
					Arrays.fill(nd, 0);

					for (int i = 0; i <= s; i++) {
						long prob = inv[i + 1];
						for (int j = 0; j <= i; j++) {
							nd[j] = (int) ((nd[j] + d[i] * prob) % MOD);
						}
					}

					int[] t = d;
					d = nd;
					nd = t;
				}

				long cur = 0;
				long curP = 1;
				for (int i = 0; i <= s; i++) {
					cur = (cur + curP * d[i]) % MOD;
					curP = curP * p % MOD;
				}
				ans = ans * cur % MOD;
			}
			out.println(ans);
		}

		private List<Factor> factorize(long n) {
			List<Factor> fs = new ArrayList<>();
			for (long p = 2; p * p <= n; p++) {
				if (n % p == 0) {
					Factor f = new Factor();
					f.p = p;
					while (n % p == 0) {
						n /= p;
						++f.s;
					}
					fs.add(f);
				}
			}
			if (n > 1) {
				Factor f = new Factor();
				f.p = n;
				f.s = 1;
				fs.add(f);
			}
			return fs;
		}

		class Factor {
			long p;
			int s;

		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

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

	}
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author sheep
 */
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);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    private static final int MOD = 1000000007;
    private long odd(int x) {
        if (x == 0) {
            return 0;
        }
        return (1 << (x - 1));
    }
    private long even(int x) {
        return (1 << (x)) - odd(x);
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int k = in.nextInt();
        // dp[full set][num]
        int[][] dp = new int[2][35];
        dp[1][0] = 1;
        for (int i = 30; i >= 0; --i) {
            int[][] next = new int[2][35];
            int bit = (k >> i) % 2;
            if (bit == 0) {
                for (int num = 0; num < 32; ++num) {
                    next[1][num] = (int) ((next[1][num] + dp[1][num] * even(num)) % MOD);
                }
            } else {
                for (int num = 0; num < 32; ++num) {
                    next[1][num] = (int) ((next[1][num] + dp[1][num] * odd(num)) % MOD);
                    next[0][num] = (int) ((next[0][num] + dp[1][num] * even(num)) % MOD);
                }

                for (int num = 0; num < 32; ++num) {
                    next[1][num + 1] = (int) ((next[1][num + 1] + dp[1][num]) % MOD);
                }
            }

            for (int num = 0; num < 32; ++num) {
                next[0][num + 1] = (int) ((next[0][num + 1] + dp[0][num]) % MOD);
                next[0][num] = (int) ((next[0][num] + dp[0][num] * (1L << (long) num)) % MOD);
            }

            dp = next;
//            print(dp);
//            System.err.println("====");
        }

        long answer = 0;
        for (int i = 0; i < 32; ++i) {
            answer = (answer + dp[0][i] + (long) dp[1][i]) % MOD;
        }

        out.println(answer);
    }
}

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

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

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

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

    }


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

public class Main {
	public static final int MAX = 1000002;

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);

		int a1 = in.nextInt();
		int b1 = in.nextInt();

		int a2 = in.nextInt();
		int b2 = in.nextInt();

		int a3 = in.nextInt();
		int b3 = in.nextInt();

		boolean result = false;

		result |= test(a1, b1, a2, b2, a3, b3);
		result |= test(a1, b1, b2, a2, a3, b3);
		result |= test(a1, b1, a2, b2, b3, a3);
		result |= test(a1, b1, b2, a2, b3, a3);

		if (result) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	public static boolean test(int a1, int b1, int a2, int b2, int a3, int b3) {

		if (a2 + a3 <= a1) {
			return Math.max(b2, b3) <= b1;
		} else if (Math.max(a2, a3) <= a1) {
			return b2 + b3 <= b1;
		} else {
			return false;
		}
	}
}


import java.util.*;

public class RPS{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int f = moveValue(scan.next());
		int m = moveValue(scan.next());
		int s = moveValue(scan.next());

		if((f == m && m == s) || (f != m && f != s && m != s)){
			System.out.println("?");
		}else{
			if(f == m){
				if(compare(s, f)){
					System.out.println("S");
				}else{
					System.out.println("?");
				}
			}else if(m == s){
				if(compare(f, m)){
					System.out.println("F");
				}else{
					System.out.println("?");
				}
			}else{
				if(compare(m, s)){
					System.out.println("M");
				}else{
					System.out.println("?");
				}
			}
		}

	}

	// rock = 0, scissors = 1, paper = 2
	public static int moveValue(String move){
		if(move.equals("rock")){
			return 0;
		}else if(move.equals("scissors")){
			return 1;
		}else{
			return 2;
		}
	}

	// Returns true if a beats b
	public static boolean compare(int a, int b){
		return (a + 1) % 3 == b;
	}
}


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

public class Main {
    static int inf = (int) (1e9 + 7);
    static int n, root = -1;
    static ArrayList<Integer> gr[];
    static ArrayList<triple> res = new ArrayList<>();
    static int sz[];

    static void build_sz(int v, int pr) {
        sz[v] = 1;
        for(int to : gr[v]) {
            if (to == pr) continue;
            build_sz(to, v);
            sz[v] += sz[to];
        }
    }

    static void find_centre(int v, int pr) {
        for(int to : gr[v]) {
            if (to != pr && sz[to] > n / 2) find_centre(to, v);
        }
        if (root == -1) root = v;
    }

    static void f(int v, int pr, int mul) {
        int cnt = 0;
        for(int to : gr[v]) {
            if (to == pr) continue;
            res.add(new triple(v, to, (1 + cnt) * mul));
            f(to, v, mul);
            cnt += sz[to];
        }
    }

    static void solve() throws IOException {
        n = sc.nextInt();
        gr = new ArrayList[n];
        for(int i = 0;i < n;i++) gr[i] = new ArrayList<>();
        sz = new int [n];

        for(int i = 0;i < n - 1;i++) {
            int v1 = sc.nextInt() - 1;
            int v2 = sc.nextInt() - 1;
            gr[v1].add(v2);
            gr[v2].add(v1);
        }

        build_sz(0, -1);
        find_centre(0, -1);
        build_sz(root, -1);

        ArrayList<Integer> to = new ArrayList<>();
        for(int i : gr[root]) to.add(i);
        Collections.sort(to, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(sz[o1], sz[o2]);
            }
        });

        int cnt1 = 0;
        int cnt2 = 0;
        for(int i : to) {
            if (cnt1 >= (n + 2) / 3) {
                res.add(new triple(root, i, (cnt2 + 1) * (cnt1 + 1)));
                f(i, root, cnt1 + 1);
                cnt2 += sz[i];
            }else{
                res.add(new triple(root, i, cnt1 + 1));
                f(i, root, 1);
                cnt1 += sz[i];
            }
        }

        for(triple i : res) {
            pw.println((i.a + 1) + " " + (i.b + 1) + " " + i.x);
        }
    }

    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        solve();
        pw.close();
    }

    static Scanner sc;
    static PrintWriter pw;

    static class Scanner {
        BufferedReader br;
        StringTokenizer st = new StringTokenizer("");

        Scanner(InputStream in) throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        Scanner(String in) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(in));
        }

        String next() throws IOException {
            while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

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

}

class triple {
    int a, b, x;
    triple(int a, int b, int x) {
        this.a = a;
        this.b = b;
        this.x = x;
    }

    triple() {}
}


import java.util.Scanner ;
import java.math.*;
import java.util.*;
public class Hi {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int a = input.nextInt();
		int b= input.nextInt();
		int ans =1 ;
		//System.out.print(gcd(3,6));
		ans+= 6 - Math.max(a, b);
		//System.out.print(ans);
		int num = ans / gcd(ans,6);
		int dum = 6/gcd(ans,6);
		System.out.printf("%d/%d",num,dum);

		}

	public static int gcd(int x, int y ){
		if(x==0)
			return y ;
		if(y==0)
			return x ;
		else{
			return (x>y)?gcd(x%y, y):gcd(x,y%x);
		}
	}

	}


import java.util.*;

public class Boser {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input = new Scanner(System.in);
        String s = input.next();
        char b[] = s.toCharArray();
        for (int i = 0; i < b.length; i++) {
            if (b[i] == '.') {
                System.out.print(0);
            }
            if (b[i] == '-' && b[i + 1] == '.') {
                System.out.print(1);
                i++;
            }
            if (b[i] == '-' && b[i + 1] == '-') {
                System.out.print(2);
                i++;
            }
        }
        System.out.println();
    }
}


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

/**
 * @author Don Li
 */
public class FreeMarket2 {

    int V = (int) 5e5 + 10;

    void solve() {
        int n = in.nextInt(), d = in.nextInt();
        int[] c = new int[n];
        for (int i = 0; i < n; i++) c[i] = in.nextInt();

        int[] dp = new int[V];
        dp[0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = V - 1; j >= c[i]; j--) {
                dp[j] |= dp[j - c[i]];
            }
        }

        int cnt = 0;
        for (int i = 0; i < V; i++) if (dp[i] > 0) cnt++;
        int[] sta = new int[cnt];
        for (int i = 0, j = 0; i < V; i++) if (dp[i] > 0) sta[j++] = i;

        int days = 0, p = 0;
        while (p < cnt) {
            int q = p;
            while (q + 1 < cnt && sta[q + 1] <= sta[p] + d) q++;
            if (p < q) {
                days++;
                p = q;
            } else {
                break;
            }
        }
        out.printf("%d %d%n", sta[p], days);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new FreeMarket2().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

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

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

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

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


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;

/**
 * Created by yash on 04/06/17.
 */
public class A {
    public static void main(String[] args) throws IOException {
        Reader reader = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(reader);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Solver solver = new Solver();
        solver.solve(br, bw);
        br.close();
        bw.close();
    }

    static class Solver {

        Utils utils;

        Solver() {
            utils = new Utils();
        }

        void solve(BufferedReader br, BufferedWriter bw) throws IOException {
            int[] args = new int[2];
            utils.getIntArray(br.readLine(), args, ":");
            int h = args[0];
            int m = args[1];
            int ans = 0;

            while (true) {
                int revh = rev(h);
                if (revh < 60 && m <= revh) {
                    ans += revh - m;
                    break;
                } else {
                    h = (h + 1) % 24;
                    ans += 60 - m;
                    m = 0;
                }
            }
            bw.write(ans + "\n");
        }

        int rev(int n) {
            int ans = 0;
            if (n < 10)
                return n * 10;

            while (n > 0) {
                ans = ans * 10;
                ans += n % 10;
                n /= 10;
            }
            return ans;
        }
    }

    static class Utils {

        void getLongArray(String s, long a[]) {
            String[] temp = s.split(" ");
            for (int i = 0; i < temp.length; i++) {
                a[i] = getLong(temp[i]);
            }
        }

        void getIntArray(String s, int a[]) {
            String[] temp = s.split(" ");
            for (int i = 0; i < temp.length; i++) {
                a[i] = getInt(temp[i]);
            }
        }

        void getIntArray(String s, int a[], String regex) {
            String[] temp = s.split(regex);
            for (int i = 0; i < temp.length; i++) {
                a[i] = getInt(temp[i]);
            }
        }

        int getInt(String s) {
            return Integer.parseInt(s);
        }

        long getLong(String s) {
            return Long.parseLong(s);
        }

        void printArray(int[] a) {
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
        }

        void printArray(long[] a) {
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
        }

        void printArray(float[] a) {
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
        }

        void printArray(double[] a) {
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
        }

        void print2DArray(int[][] a) {
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    System.out.print(a[i][j] + " ");
                }
                System.out.println();
            }
            System.out.println();
        }

        void print2DArray(Object[][] a) {
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    System.out.print(a[i][j] + " ");
                }
                System.out.println();
            }
            System.out.println();
        }

    }
}


import java.util.*;
import java.util.Collections;

public class Contest
{
	public static void main(String args[])
	{

		Scanner sc=new Scanner(System.in);

		int mp,vp,c,d;
		int misha,vasya;

		mp=sc.nextInt();
		vp=sc.nextInt();
		c=sc.nextInt();
		d=sc.nextInt();

		misha=Math.max((3*mp)/10, mp-(mp*c)/250);

		vasya=Math.max((3*vp)/10, vp-(vp*d)/250);

		if(misha>vasya)
			System.out.println("Misha");
		else if(vasya>misha)
			System.out.println("Vasya" );
		else
			System.out.println("Tie" );

		sc.close();
	}
}


//package All_in_all;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

import static java.lang.Math.abs;
import static java.lang.Math.round;

/**
 * Created by nikitos on 23.08.17.
 */

public class otrezok {

    public StreamTokenizer t;

    public int nextInt() throws IOException {
        t.nextToken();
        return (int) t.nval;
    }

    public String nextString() throws IOException {
        t.nextToken();
        return t.sval;
    }

    public void start() throws IOException {
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(buf.readLine());

        for (int i = 0; i < n; i++) {
            String[] lit = buf.readLine().split(" ");
            long a = Long.parseLong(lit[0]);
            long b = Long.parseLong(lit[1]);

            if (a - b != 1) {
                System.out.println("NO");
            } else {
                long c = a + b;
                System.out.println(checkIsItANaturalNumber(c)? "YES" : "NO");
            }
        }
    }

    private boolean checkIsItANaturalNumber(long n) {
        for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
            if (n % i == 0) {
                return false;
            }
        }

        return true;
    }

    public static void main(String[] args) throws IOException {
        new otrezok().start();
    }

}


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

public class Main implements Runnable{
    public static void main(String[] args){
        //new Thread(null,new Main(),"Thread-1",1024*1024*10).start();
        new Main().run();
    }
    int mod=1000000007;
    int n,k,m;
    private void solve() throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        n=in.nextInt();k=in.nextInt();m=in.nextInt();
        int[][]ma=new int[(k+1)*(1<<m)][(k+1)*(1<<m)];
        for(int i=0;i<=k;i++) {
            for (int j = 0; j < (1 << m); j++) {
                ma[trans(i,j>>1)][trans(i,j)]=1;
                if(i<k)ma[trans(i+1,j>>1|(1<<m-1))][trans(i,j)]=Integer.bitCount(j)+1;
            }
        }
        ma=FastPowMod(ma,n);
        long ans=0;
        for(int i=trans(k,0);i<ma.length;i++)ans+=ma[i][0];
        out.println(ans%mod);
        out.flush();
    }
    public int[][] FastPowMod(int[][] a,int b){
        int[][] ans=new int[a.length][a.length];
        for(int i=0;i<a.length;i++)ans[i][i]=1;
        while(b>0){
            if((b&1)==1)
                ans=modMul(ans,a);
            a=modMul(a,a);
            b>>=1;
        }
        return ans;
    }
    public int[][] modMul(int[][]a,int[][]b){
        int row=a.length,column=b[0].length;
        int len=b.length;
        int[][] ans=new int[row][column];
        for(int i=0;i<row;i++){
            for(int j=0;j<len;j++){
                //if(a[i][j]==0)continue;//稀疏矩阵优化
                for(int k=0;k<column;k++){
                    ans[i][k]+=(long)a[i][j]*b[j][k]%mod;
                    ans[i][k]%=mod;
                }
            }
        }
        return ans;
    }

    int trans(int x,int y){
        return x*(1<<m)+y;
    }
    @Override
    public void run() {
        try {
            solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    void shuffle(int[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r; i>l+1; i--) {
            int j=rnd.nextInt(i),tmp=a[j];
            a[j]=a[i-1];
            a[i-1]=tmp;
        }
    }
    void shuffle(Object[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r; i>l+1; i--) {
            int j=rnd.nextInt(i);
            Object tmp=a[j];
            a[j]=a[i-1];
            a[i-1]=tmp;
        }
    }
    void shuffle(long[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r; i>l+1; i--) {
            int j=rnd.nextInt(i);
            long tmp=a[j];
            a[j]=a[i-1];
            a[i-1]=tmp;
        }
    }
    class InputReader{
        StreamTokenizer tokenizer;
        public InputReader(InputStream stream){
            tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));
            tokenizer.ordinaryChars(33,126);
            tokenizer.wordChars(33,126);
        }
        public String next() throws IOException {
            tokenizer.nextToken();
            return tokenizer.sval;
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public boolean hasNext() throws IOException {
            int res=tokenizer.nextToken();
            tokenizer.pushBack();
            return res!=tokenizer.TT_EOF;
        }
    }
}


import java.util.*;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class Main{
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

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

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

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

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

            if (neg)
                return -ret;
            return ret;
        }

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

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

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

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

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    static void p(String s){
        System.out.println(s);
    }
    static void p(int s){
        System.out.println(s);
    }
    static void p(long s){
        System.out.println(s);
    }
    static void p(int[] s){
        System.out.println(Arrays.toString(s));
    }
    static void p2(String s){
        System.out.print(s);
    }

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        char[] str = (s.next()).toCharArray();
        Set<Character> v = new HashSet<>();
        v.add('u');
        v.add('o');
        v.add('i');
        v.add('e');
        v.add('a');
        v.add('n');
        for(int i = 0;i<str.length-1;i++){
            if(!v.contains(str[i]) && str[i+1] == 'n'){
                p("NO");
                return;
            }
            if(v.contains(str[i])) continue;
            if(v.contains(str[i+1])) continue;
            p("NO");
            return;
        }
        if(!v.contains(str[str.length-1])){
            p("NO");
            return;
        }
        p("YES");
    }
}