defmodule Main do
  def main() do
    input = IO.gets("") |> String.trim() |> String.split() |> Enum.map(&(String.to_integer(&1)))
    n = input |> Enum.at(0)
    m = input |> Enum.at(1)
    heights = get_i()
              |> Enum.map(&([&1, []]))
    heights = get_inp(m, heights)
    heights
    |> Enum.map(&(ev(&1)))
    |> Enum.filter(&(&1==:ok))
    |> Enum.count()
    |>IO.puts
  end


  def ev([ha, list]) do
    if Enum.all?(list, &(&1 < ha)) do
      :ok
    else
      :bad
    end
  end

  def get_i() do
    input = IO.gets("") |> String.trim() |> String.split() |> Enum.map(&(String.to_integer(&1)))
  end

  def get_inp(0,  h), do: h
  def get_inp(num, heights) do
    [a, b] = IO.gets("") |> String.trim() |> String.split()|> Enum.map(&(String.to_integer(&1)))
    heights = inn(a, b, heights)
    get_inp(num-1, heights)
  end

  def inn(a, b, heights) do
    [aa, li_a]=Enum.at(heights, a-1)
    [bb, li_b]=Enum.at(heights, b-1)
    result_a = [aa, li_a ++ [bb]]
    result_b = [bb, li_b ++ [aa]]

    heights
    |> Enum.with_index()
    |> Enum.map(fn x ->
      a = a-1
      b = b-1
      case elem(x, 1) do
        ^a -> {result_a, 0}
        ^b -> {result_b, 0}
        _ -> x
      end
    end)
    |> Enum.map(fn x -> elem(x, 0) end)
  end
end