Under construction

Still being built. Things may change

Ski Cows

Interview

Time limit1sMemory limit1024 MB

Summary
Count the downhill ski routes from the highest landmark to the lowest, where each ski path between two landmarks counts as a separate option.
Level

Medium5 of 10

Topics
Dynamic programming, Graph, Sorting
Solved
No attempts yet

Problem

Farmer John's cows behaved well, so he sends them on a winter vacation to visit USACO head coach Rob K. Rob lives in Colorado and likes to take the cows skiing. He needs your help to find the best ski location to visit. He wants a mountain with many routes from top to bottom, so the cows do not get bored.

The input file describes a mountain and its interesting landmarks. It gives each landmark's elevation and the ski paths between landmarks.

The landmark with the largest elevation is the top of the mountain, and the landmark with the smallest elevation is the bottom. Every ski route starts at the top and follows a sequence of ski paths, moving from landmark to landmark downhill, until it reaches the bottom.

Compute the number of different possible ski routes.

Input

The first line contains two integers: NN, 2≤N≤2002 \le N \le 200, the number of landmarks on the mountain; and MM, the number of ski paths, where 1≤M≤50001 \le M \le 5000. A ski path connects two landmarks.

Next come NN space-separated positive integers smaller than 1,000,000, giving the elevation of each landmark in order (landmark 1, landmark 2, ..., landmark NN). All elevations are unique. The integers are given 10 per line, except possibly the last line.

Finally come MM space-separated pairs of integers, each in the range [1..N][1..N], listing the two landmarks each ski path connects. Each pair connects two different landmarks, and each pair is unordered. Several ski paths may connect the same pair of landmarks. The pairs are given 10 pairs per line, except possibly the last line.

Output

A single integer: the total number of possible paths down the mountain.

Examples1

  1. Example 1

    Input
    4 5
    500 400 300 200
    1 2 2 3 3 4 1 4 2 4
    
    Expected output
    3