// ternary operation
#[allow(unused_macros)]
macro_rules! _if {
  ($_test:expr, $_then:expr, $_else:expr) => {
    if $_test { $_then } else { $_else }
  };
  ($_test:expr, $_pat:pat, $_then:expr, $_else:expr) => {
    match $_test {
      $_pat => $_then,
      _     => $_else
    }
  };
}

use std::io::{ stdin, stdout, Write };
use my::WriteWith;
use std::cmp;

#[inline(always)]
fn cost(ary: &[i32]) -> i32 {
  if ary.len() == 1 {
    return ary[0].abs();
  }
  cmp::min(ary[0].abs(), ary[ary.len() - 1].abs()) + (ary[ary.len() - 1] - ary[0]).abs()
}

#[inline(always)]
fn arc101_a() {
  let stdin  = stdin();
  let stdout = stdout();
  let (mut scanner, mut writer) = my::rw(12, stdin.lock(), stdout.lock());
  let mut itoa = my::ItoA::with_capacity(10);

  let n = scanner.uint_until::<usize>(my::SP);
  let k = scanner.uint_until::<usize>(my::LF);

  if k == 1 {
    let mut ans = <i32>::max_value();
    for _ in 0..n - 1 {
      ans = cmp::min(ans, scanner.int_until::<i32>(my::SP));
    }
    ans = cmp::min(ans, scanner.int_until::<i32>(my::LF));
    writer.write_with(itoa.from_i32(ans), b"\n").unwrap();
    writer.flush().unwrap();
    return;
  }

  let mut vec = Vec::with_capacity(n);

  if n == k {
    for _ in 0..k - 1 {
      vec.push(scanner.int_until::<i32>(my::SP));
    }
    vec.push(scanner.int_until::<i32>(my::LF));

    let ans = cost(&vec[0..]);

    writer.write_with(itoa.from_i32(ans), b"\n").unwrap();
    writer.flush().unwrap();
    return;
  }

  for _ in 0..k {
    vec.push(scanner.int_until::<i32>(my::SP));
  }
  let mut ans = cost(&vec[0..]);

  for i in k..n - 1 {
    vec.push(scanner.int_until::<i32>(my::SP));
    ans = cmp::min(ans, cost(&vec[i - (k - 1)..]));
  }
  vec.push(scanner.int_until::<i32>(my::LF));
  ans = cmp::min(ans, cost(&vec[n - k..]));

  writer.write_with(itoa.from_i32(ans), b"\n").unwrap();
  writer.flush().unwrap();
}

fn main() {
  arc101_a();
}

//------------------------------------------------------------------------
mod my {
  use std::hash::Hasher;
  use std::hash::BuildHasher;

  pub struct MyHasher(u64);

  impl Default for MyHasher {
    #[inline(always)]
    fn default() -> Self {
      MyHasher(0x00)
    }
  }

  impl BuildHasher for MyHasher {
    type Hasher = MyHasher;

    #[inline(always)]
    fn build_hasher(&self) -> Self::Hasher {
      Self::Hasher::default()
    }
  }

  impl Hasher for MyHasher {
    #[inline(always)]
    fn finish(&self) -> u64 {
      self.0
    }

    #[inline(always)]
    fn write(&mut self, bytes: &[u8]) {
      self.0 = 0;
      for i in 0..bytes.len() {
        self.0 ^= (bytes[i] as u64) << (8 * (i % 8));
      }
    }
  }

  //----------------------------------------------------------------------
  use std::io::{ self, BufRead, BufReader, Write, BufWriter };
  use std::fmt::Debug;
  use std::ops::{ Add, Sub, Mul, Neg, Rem };
  use std::str::{ self, FromStr };
  use std::mem;

  const PLUS_SIGN : u8 = b'+';
  const MINUS_SIGN: u8 = b'-';
  const ASCII_0   : u8 = b'0';
  const ASCII_9   : u8 = b'9';

  pub const SP    : u8 = b' ';
  pub const LF    : u8 = b'\n';

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn rotate_right<T>(ary: &mut [T])
    where T: Copy +
             Debug
  {
    if ary.len() <= 1 {
      return;
    }

    let len = ary.len() - 1;
    let tmp = ary[len];
    for i in 0..len {
      ary[len - i] = ary[len - i - 1];
    }
    ary[0] = tmp;
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn rotate_left<T>(ary: &mut [T])
    where T: Copy +
             Debug
  {
    if ary.len() <= 1 {
      return;
    }

    let len = ary.len() - 1;
    let tmp = ary[0];
    for i in 0..len {
      ary[i] = ary[i + 1];
    }
    ary[len] = tmp;
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn gcd<T>(x: T, y: T) -> T
    where T: Rem<Output=T> +
             Default +
             PartialEq +
             Copy +
             Debug
  {
    _if!(y == T::default(),
      x,
      gcd(y, x % y))
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn intersection<T>(mut x: (T, T), mut y: (T, T)) -> Option<(T, T)>
    where T: PartialOrd +
             Copy +
             Debug
  {
    if x.0 > x.1 {
      mem::swap(&mut x.0, &mut x.1);
    }
    if y.0 > y.1 {
      mem::swap(&mut y.0, &mut y.1);
    }

    if x.0 >= y.1 || x.1 <= y.0 {
      return None;
    }

    if x.0 < y.0 {
      x.0 = y.0;
    }
    if x.1 > y.1 {
      x.1 = y.1;
    }

    Some(x)
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_digit(b: u8) -> bool {
    _if!(b >= ASCII_0 && b <= ASCII_9,
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_uppercase(b: u8) -> bool {
    _if!(b >= b'A' && b <= b'Z',
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_lowercase(b: u8) -> bool {
    _if!(b >= b'a' && b <= b'z',
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_alphabetic(b: u8) -> bool {
    _if!(is_ascii_uppercase(b) || is_ascii_lowercase(b),
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn to_ascii_lowercase(b: u8) -> u8 {
    _if!(is_ascii_uppercase(b),
      b + 0x20,
      b)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn to_ascii_uppercase(b: u8) -> u8 {
    _if!(is_ascii_lowercase(b),
      b - 0x20,
      b)
  }

  //----------------------------------------------------------------------
  pub trait WriteWith {
    fn write_with(&mut self, buf: &[u8], delim: &[u8]) -> io::Result<usize>;
  }

  impl<W> WriteWith for BufWriter<W>
    where W: io::Write
  {
    #[allow(dead_code)]
    #[inline(always)]
    fn write_with(&mut self, buf: &[u8], delim: &[u8]) -> io::Result<usize>
    {
      Ok(self.write(buf)? + self.write(delim)?)
    }
  } // impl<W> WriteWith for BufWriter<W>

  //----------------------------------------------------------------------
  macro_rules! pub_fn_ItoA_from_ty {
    (uint, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      #[inline(always)]
      pub fn $name(&mut self, mut n: $_type) -> &[u8] {
        self.buf.clear();
        if n == 0 {
          self.buf.push(ASCII_0);
          return self.buf.as_slice();
        }

        while n > 0 {
          self.buf.push((n % 10) as u8 + ASCII_0);
          n /= 10;
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};

    (int, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      #[inline(always)]
      pub fn $name(&mut self, mut n: $_type) -> &[u8] {
        self.buf.clear();
        if n == 0 {
          self.buf.push(ASCII_0);
          return self.buf.as_slice();
        }

        let mut negative = false;
        if n.is_negative() {
          negative = true;
          n = n.abs();
        }

        while n > 0 {
          self.buf.push((n % 10) as u8 + ASCII_0);
          n /= 10;
        }
        if negative {
          self.buf.push(MINUS_SIGN);
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};
  }

  #[derive(Debug)]
  pub struct ItoA {
    buf: Vec<u8>,
  }

  impl ItoA {
    #[allow(dead_code)]
    #[inline(always)]
    pub fn new() -> Self {
      ItoA {
        buf: Vec::new(),
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn with_capacity(cap: usize) -> Self {
      ItoA {
        buf: Vec::with_capacity(cap),
      }
    }

    pub_fn_ItoA_from_ty!(
      uint,
      from_usize => usize,
      from_u8    => u8,
      from_u16   => u16,
      from_u32   => u32,
      from_u64   => u64
    );

    pub_fn_ItoA_from_ty!(
      int,
      from_isize => isize,
      from_i8    => i8,
      from_i16   => i16,
      from_i32   => i32,
      from_i64   => i64
    );
  } // impl ItoA

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn rw<R, W>(cap: usize, r: R, w: W) -> (Scanner<BufReader<R>>, BufWriter<W>)
    where R: BufRead,
          W: io::Write
  {
    (
      Scanner::with_capacity(cap, BufReader::new(r)),
      BufWriter::new(w)
    )
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn r<R>(cap: usize, r: R) -> Scanner<BufReader<R>>
    where R: BufRead
  {
    Scanner::with_capacity(cap, BufReader::new(r))
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn w<W>(w: W) -> BufWriter<W>
    where W: io::Write
  {
    BufWriter::new(w)
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[derive(Debug)]
  pub enum Direction {
    Horizontal,
    Vertical
  }

  #[derive(Debug)]
  pub struct Scanner<R> {
    reader: R,
    buf   : Vec<u8>,
  }

  impl<R> Scanner<R>
    where R: BufRead
  {
    #[allow(dead_code)]
    #[inline(always)]
    pub fn new(reader: R) -> Self {
      Scanner {
        reader: reader,
        buf   : Vec::new(),
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn with_capacity(cap: usize, reader: R) -> Self {
      Scanner {
        reader: reader,
        buf   : Vec::with_capacity(cap),
      }
    }

    //--------------------------------------------------------------------
    #[inline(always)]
    fn read_until(&mut self, delim: u8) -> usize {
      self.buf.clear();
      let mut len = self.reader.read_until(delim, &mut self.buf).unwrap();
      if len == 0 {
        return len;
      }

      len -= 1;
      if self.buf[len] == delim {
        self.buf.truncate(len);
      }
      len
    }

    //--------------------------------------------------------------------
    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn parse_until<T>(&mut self, delim: u8) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.read_until(delim);
      unsafe { str::from_utf8_unchecked(&self.buf) }
        .parse()
        .unwrap()
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn byte_until(&mut self, delim: u8) -> Vec<u8> {
      self.read_until(delim);
      self.buf.clone()
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn string_until(&mut self, delim: u8) -> String {
      unsafe { String::from_utf8_unchecked(self.byte_until(delim)) }
    }

    //--------------------------------------------------------------------
    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_until<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.read_until(delim);
      let mut n = T::default();
      if len == 0 {
        return n;
      }

      let mut i = 0;
      if self.buf[i] == PLUS_SIGN {
        i += 1;
      }

      for b in &self.buf[i..] {
        n = (n * T::from(10)) + T::from(b - ASCII_0);
      }

      n
    }

    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_until<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.read_until(delim);
      let mut n = T::default();
      if len == 0 {
        return n;
      }

      let mut i = 0;
      let mut negative = false;
      if self.buf[i] == MINUS_SIGN {
        negative = true;
        i += 1;
      } else if self.buf[i] == PLUS_SIGN {
        i += 1;
      }

      for b in &self.buf[i..] {
        n = (n * T::from(10)) + T::from(b - ASCII_0);
      }

      _if!(negative,
        n.neg(),
        n)
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.uint_until(delim));
      }
      vec.push(self.uint_until(LF));
      vec
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.int_until(delim));
      }
      vec.push(self.int_until(LF));
      vec
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.uint_until(LF);
      self.uint_vec(n, Direction::Horizontal)
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.uint_until(LF);
      self.int_vec(n, Direction::Horizontal)
    }

    // N M
    // s11 s12 s13 ... s1M
    // s21 s22 s23 ... s2M
    // s31 s32 s33 ... s3M
    //   :
    // sN1 sN2 sN3 ... sNM
    // -> [
    //      [n11, n12, n13, ..., n1M],
    //      [n21, n22, n23, ..., n2M],
    //      [n31, n32, n33, ..., n3M],
    //          :
    //      [nN1, nN2, nN3, ..., nNM],
    //    ]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.uint_vec(m, Direction::Horizontal));
      }
      vec
    }

    // N M
    // s11 s12 s13 ... s1M
    // s21 s22 s23 ... s2M
    // s31 s32 s33 ... s3M
    //   :
    // sN1 sN2 sN3 ... sNM
    // -> [
    //      [n11, n12, n13, ..., n1M],
    //      [n21, n22, n23, ..., n2M],
    //      [n31, n32, n33, ..., n3M],
    //          :
    //      [nN1, nN2, nN3, ..., nNM],
    //    ]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.int_vec(m, Direction::Horizontal));
      }
      vec
    }

  } // impl<R> Scanner<R>

} // mod my


// ternary operation
#[allow(unused_macros)]
macro_rules! _if {
  ($_test:expr, $_then:expr, $_else:expr) => {
    if $_test { $_then } else { $_else }
  };
  ($_test:expr, $_pat:pat, $_then:expr, $_else:expr) => {
    match $_test {
      $_pat => $_then,
      _     => $_else
    }
  };
}

use std::io::{ stdin, stdout, Write };
use my::WriteWith;
use std::cmp;

#[inline(always)]
fn cost(ary: &[i32]) -> i32 {
  if ary.len() == 1 {
    return ary[0].abs();
  }
  cmp::min(ary[0].abs(), ary[ary.len() - 1].abs()) + (ary[ary.len() - 1] - ary[0]).abs()
}

#[inline(always)]
fn arc101_a() {
  let stdin  = stdin();
  let stdout = stdout();
  let (mut scanner, mut writer) = my::rw(12, stdin.lock(), stdout.lock());
  let mut itoa = my::ItoA::with_capacity(10);

  let n = scanner.uint_until::<usize>(my::SP);
  let k = scanner.uint_until::<usize>(my::LF);

  if k == 1 {
    let mut ans = <i32>::max_value();

    scanner.int_n(n, my::Direction::Horizontal, | x | {
      ans = cmp::min(ans, x);
    });

    writer.write_with(itoa.from_i32(ans), b"\n").unwrap();
    writer.flush().unwrap();
    return;
  }

  if n == k {
    let mut vec = Vec::with_capacity(n);

    scanner.int_n(k, my::Direction::Horizontal, | x | {
      vec.push(x);
    });

    let ans = cost(&vec);

    writer.write_with(itoa.from_i32(ans), b"\n").unwrap();
    writer.flush().unwrap();
    return;
  }

  let mut vec = Vec::with_capacity(n);

  for _ in 0..k {
    vec.push(scanner.int_until::<i32>(my::SP));
  }

  let mut ans = cost(&vec[0..]);

  scanner.int_n(n - k, my::Direction::Horizontal, | x | {
    vec.push(x);
    ans = cmp::min(ans, cost(&vec[vec.len() - k..]));
  });

  writer.write_with(itoa.from_i32(ans), b"\n").unwrap();
  writer.flush().unwrap();
}

fn main() {
  arc101_a();
}

//------------------------------------------------------------------------
mod my {
  use std::hash::Hasher;
  use std::hash::BuildHasher;

  pub struct MyHasher(u64);

  impl Default for MyHasher {
    #[inline(always)]
    fn default() -> Self {
      MyHasher(0x00)
    }
  }

  impl BuildHasher for MyHasher {
    type Hasher = MyHasher;

    #[inline(always)]
    fn build_hasher(&self) -> Self::Hasher {
      Self::Hasher::default()
    }
  }

  impl Hasher for MyHasher {
    #[inline(always)]
    fn finish(&self) -> u64 {
      self.0
    }

    #[inline(always)]
    fn write(&mut self, bytes: &[u8]) {
      self.0 = 0;
      for i in 0..bytes.len() {
        self.0 ^= (bytes[i] as u64) << (8 * (i % 8));
      }
    }
  }

  //----------------------------------------------------------------------
  use std::io::{ self, BufRead, BufReader, Write, BufWriter };
  use std::fmt::Debug;
  use std::ops::{ Add, Sub, Mul, Neg, Rem };
  use std::str::{ self, FromStr };
  use std::mem;

  const PLUS_SIGN : u8 = b'+';
  const MINUS_SIGN: u8 = b'-';
  const ASCII_0   : u8 = b'0';
  const ASCII_9   : u8 = b'9';

  pub const SP    : u8 = b' ';
  pub const LF    : u8 = b'\n';

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn rotate_right<T>(ary: &mut [T])
    where T: Copy +
             Debug
  {
    if ary.len() <= 1 {
      return;
    }

    let len = ary.len() - 1;
    let tmp = ary[len];
    for i in 0..len {
      ary[len - i] = ary[len - i - 1];
    }
    ary[0] = tmp;
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn rotate_left<T>(ary: &mut [T])
    where T: Copy +
             Debug
  {
    if ary.len() <= 1 {
      return;
    }

    let len = ary.len() - 1;
    let tmp = ary[0];
    for i in 0..len {
      ary[i] = ary[i + 1];
    }
    ary[len] = tmp;
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn gcd<T>(x: T, y: T) -> T
    where T: Rem<Output=T> +
             Default +
             PartialEq +
             Copy +
             Debug
  {
    _if!(y == T::default(),
      x,
      gcd(y, x % y))
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn intersection<T>(mut x: (T, T), mut y: (T, T)) -> Option<(T, T)>
    where T: PartialOrd +
             Copy +
             Debug
  {
    if x.0 > x.1 {
      mem::swap(&mut x.0, &mut x.1);
    }
    if y.0 > y.1 {
      mem::swap(&mut y.0, &mut y.1);
    }

    if x.0 >= y.1 || x.1 <= y.0 {
      return None;
    }

    if x.0 < y.0 {
      x.0 = y.0;
    }
    if x.1 > y.1 {
      x.1 = y.1;
    }

    Some(x)
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_digit(b: u8) -> bool {
    _if!(b >= ASCII_0 && b <= ASCII_9,
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_uppercase(b: u8) -> bool {
    _if!(b >= b'A' && b <= b'Z',
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_lowercase(b: u8) -> bool {
    _if!(b >= b'a' && b <= b'z',
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_alphabetic(b: u8) -> bool {
    _if!(is_ascii_uppercase(b) || is_ascii_lowercase(b),
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn to_ascii_lowercase(b: u8) -> u8 {
    _if!(is_ascii_uppercase(b),
      b + 0x20,
      b)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn to_ascii_uppercase(b: u8) -> u8 {
    _if!(is_ascii_lowercase(b),
      b - 0x20,
      b)
  }

  //----------------------------------------------------------------------
  pub trait WriteWith {
    fn write_with(&mut self, buf: &[u8], delim: &[u8]) -> io::Result<usize>;
  }

  impl<W> WriteWith for BufWriter<W>
    where W: io::Write
  {
    #[allow(dead_code)]
    #[inline(always)]
    fn write_with(&mut self, buf: &[u8], delim: &[u8]) -> io::Result<usize>
    {
      Ok(self.write(buf)? + self.write(delim)?)
    }
  } // impl<W> WriteWith for BufWriter<W>

  //----------------------------------------------------------------------
  macro_rules! pub_fn_ItoA_from_ty {
    (uint, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      #[inline(always)]
      pub fn $name(&mut self, mut n: $_type) -> &[u8] {
        self.buf.clear();
        if n == 0 {
          self.buf.push(ASCII_0);
          return self.buf.as_slice();
        }

        while n > 0 {
          self.buf.push((n % 10) as u8 + ASCII_0);
          n /= 10;
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};

    (int, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      #[inline(always)]
      pub fn $name(&mut self, mut n: $_type) -> &[u8] {
        self.buf.clear();
        if n == 0 {
          self.buf.push(ASCII_0);
          return self.buf.as_slice();
        }

        let mut negative = false;
        if n.is_negative() {
          negative = true;
          n = n.abs();
        }

        while n > 0 {
          self.buf.push((n % 10) as u8 + ASCII_0);
          n /= 10;
        }
        if negative {
          self.buf.push(MINUS_SIGN);
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};
  }

  #[derive(Debug)]
  pub struct ItoA {
    buf: Vec<u8>,
  }

  impl ItoA {
    #[allow(dead_code)]
    #[inline(always)]
    pub fn new() -> Self {
      ItoA {
        buf: Vec::new(),
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn with_capacity(cap: usize) -> Self {
      ItoA {
        buf: Vec::with_capacity(cap),
      }
    }

    pub_fn_ItoA_from_ty!(
      uint,
      from_usize => usize,
      from_u8    => u8,
      from_u16   => u16,
      from_u32   => u32,
      from_u64   => u64
    );

    pub_fn_ItoA_from_ty!(
      int,
      from_isize => isize,
      from_i8    => i8,
      from_i16   => i16,
      from_i32   => i32,
      from_i64   => i64
    );
  } // impl ItoA

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn rw<R, W>(cap: usize, r: R, w: W) -> (Scanner<BufReader<R>>, BufWriter<W>)
    where R: BufRead,
          W: io::Write
  {
    (
      Scanner::with_capacity(cap, BufReader::new(r)),
      BufWriter::new(w)
    )
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn r<R>(cap: usize, r: R) -> Scanner<BufReader<R>>
    where R: BufRead
  {
    Scanner::with_capacity(cap, BufReader::new(r))
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn w<W>(w: W) -> BufWriter<W>
    where W: io::Write
  {
    BufWriter::new(w)
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[derive(Debug)]
  pub enum Direction {
    Horizontal,
    Vertical
  }

  #[derive(Debug)]
  pub struct Scanner<R> {
    reader: R,
    buf   : Vec<u8>,
  }

  impl<R> Scanner<R>
    where R: BufRead
  {
    #[allow(dead_code)]
    #[inline(always)]
    pub fn new(reader: R) -> Self {
      Scanner {
        reader: reader,
        buf   : Vec::new(),
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn with_capacity(cap: usize, reader: R) -> Self {
      Scanner {
        reader: reader,
        buf   : Vec::with_capacity(cap),
      }
    }

    //--------------------------------------------------------------------
    #[inline(always)]
    fn read_until(&mut self, delim: u8) -> usize {
      self.buf.clear();
      let mut len = self.reader.read_until(delim, &mut self.buf).unwrap();
      if len == 0 {
        return len;
      }

      len -= 1;
      if self.buf[len] == delim {
        self.buf.truncate(len);
      }
      len
    }

    //--------------------------------------------------------------------
    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn parse_until<T>(&mut self, delim: u8) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.read_until(delim);
      unsafe { str::from_utf8_unchecked(&self.buf) }
        .parse()
        .unwrap()
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn byte_until(&mut self, delim: u8) -> Vec<u8> {
      self.read_until(delim);
      self.buf.clone()
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn string_until(&mut self, delim: u8) -> String {
      unsafe { String::from_utf8_unchecked(self.byte_until(delim)) }
    }

    //--------------------------------------------------------------------
    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_until<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.read_until(delim);
      let mut n = T::default();
      if len == 0 {
        return n;
      }

      let mut i = 0;
      if self.buf[i] == PLUS_SIGN {
        i += 1;
      }

      for b in &self.buf[i..] {
        n = (n * T::from(10)) + T::from(b - ASCII_0);
      }

      n
    }

    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_until<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.read_until(delim);
      let mut n = T::default();
      if len == 0 {
        return n;
      }

      let mut i = 0;
      let mut negative = false;
      if self.buf[i] == MINUS_SIGN {
        negative = true;
        i += 1;
      } else if self.buf[i] == PLUS_SIGN {
        i += 1;
      }

      for b in &self.buf[i..] {
        n = (n * T::from(10)) + T::from(b - ASCII_0);
      }

      _if!(negative,
        n.neg(),
        n)
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_n<T, F>(&mut self, n: usize, dir: Direction, mut func: F)
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug,
            F: ::std::ops::FnMut(T)
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      for _ in 0..n - 1 {
        func(self.int_until(delim));
      }
      func(self.int_until(LF));
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.uint_until(delim));
      }
      vec.push(self.uint_until(LF));
      vec
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.int_until(delim));
      }
      vec.push(self.int_until(LF));
      vec
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.uint_until(LF);
      self.uint_vec(n, Direction::Horizontal)
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.uint_until(LF);
      self.int_vec(n, Direction::Horizontal)
    }

    // N M
    // s11 s12 s13 ... s1M
    // s21 s22 s23 ... s2M
    // s31 s32 s33 ... s3M
    //   :
    // sN1 sN2 sN3 ... sNM
    // -> [
    //      [n11, n12, n13, ..., n1M],
    //      [n21, n22, n23, ..., n2M],
    //      [n31, n32, n33, ..., n3M],
    //          :
    //      [nN1, nN2, nN3, ..., nNM],
    //    ]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.uint_vec(m, Direction::Horizontal));
      }
      vec
    }

    // N M
    // s11 s12 s13 ... s1M
    // s21 s22 s23 ... s2M
    // s31 s32 s33 ... s3M
    //   :
    // sN1 sN2 sN3 ... sNM
    // -> [
    //      [n11, n12, n13, ..., n1M],
    //      [n21, n22, n23, ..., n2M],
    //      [n31, n32, n33, ..., n3M],
    //          :
    //      [nN1, nN2, nN3, ..., nNM],
    //    ]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.int_vec(m, Direction::Horizontal));
      }
      vec
    }

  } // impl<R> Scanner<R>

} // mod my


use proconio::input;

fn main() {
  input! {
    n: usize,
    mut k: usize,
    mut vals: [isize;n]
  }

  for (i, v) in vals.iter().enumerate() {
    if v == &0 {
      k -= 1;
      vals.remove(i);
      break;
    }
  }

  if k == 0 {
    println!("0");
    return
  }

  let mut min = isize::max_value();
  let mut i = k-1;
  while i < vals.len() && vals[i] < 0 {
    min = std::cmp::min(vals[i-k+1].abs(), min);
    i += 1;
  }

  let mut temp = 0;
  let mut last = 0;
  for i in 0..k {
    temp += (last - vals[i]).abs();
    last = vals[i];
  }

  min = std::cmp::min(min, temp);
  for i in k..vals.len() {
    temp -= vals[i-k].abs();
    temp -= (vals[i-k+1] - vals[i-k]).abs();
    temp += vals[i-k+1].abs();
    temp += (vals[i] - last).abs();
    last = vals[i];
    min = std::cmp::min(min, temp);
  }

  println!("{}", min);
}


use proconio::input;

fn main() {
  input! {
    n: usize,
    mut k: usize,
    mut vals: [isize;n]
  }

  for (i, v) in vals.iter().enumerate() {
    if v == &0 {
      k -= 1;
      vals.remove(i);
      break;
    }
  }

  if k == 0 {
    println!("0");
    return
  }

  let mut min = 0;
  let mut last = 0;
  for i in 0..k {
    min += (last - vals[i]).abs();
    last = vals[i];
  }

  let mut temp = min;
  for i in k..vals.len() {
    temp -= vals[i-k].abs();
    temp -= (vals[i-k+1] - vals[i-k]).abs();
    temp += vals[i-k+1].abs();
    temp += (vals[i] - last).abs();
    last = vals[i];
    min = std::cmp::min(min, temp);
  }

  println!("{}", min);
}


use std::cmp::min;
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        arr: [isize; n],
    }

    let mut ans = std::isize::MAX;
    for i in 0..n-k+1 {
        let s = &arr[i..i+k];
        let &f = s.first().unwrap();
        let &l = s.last().unwrap();
        if f < 0 && l > 0 { ans = min(ans, l-2*f) }
        else if f < 0 { ans = min(ans, 0-f) }
        else { ans = min(ans, l) }
    }

    println!("{}", ans);
}


// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    let g = gcd(m, n)
    return m / g * n
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {

    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt

    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2

        if Int(ary[mid])! < key {
            left = mid

        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }

    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

/// 1〜nまでの数字からなる辞書順列のm番目の順列を返す
func permutation(_ n: Int, _ m: Int) -> [Int] {
    var m = m

    var temp = [Int](repeating: 0, count: n)
    var surplus = [Int](repeating: 0, count: n)

    for i in 1...n {
        temp[i - 1] = i

        surplus[n - i] = m % i
        m = m / i
    }

    var order = [Int](repeating: 0, count: n)

    for i in 0..<n {
        order[i] = temp[surplus[i]]
        var j = surplus[i]
        while j + 1 < n {
            temp[j] = temp[j + 1]
            j += 1
        }
    }
    return order
}
func mod() -> Int {
    return Int(pow(10.0, 9.0)) + 7
}

func nPk(_ n: Int, _ k: Int) -> Int {
    var (n, k) = (n, k)
    var res = 1
    while k > 0 {
        res *= n
        res %= mod()
        n -= 1
        k -= 1
    }
    return res
}

func main() {
    let input = readInts()
    let (N, K) = (input[0], input[1])
    let x = readInts()
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var ans = Int.max
    for i in 0..<N - K + 1 {
        let (left, right) = (x[i], x[i + K - 1])
        ans = min(ans, min(abs(left), abs(right)) + right - left)
    }

    print(ans)

}
main()


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, K) = (input[0], input[1]-1)
let x = readLine()!.characters.split(" ").map{Int(String($0))!}
var ans = 300000000
for i in 0..<N-K {
    let time = min(abs(x[i]), abs(x[i+K])) + abs(x[i]-x[i+K])
    ans = min(time, ans)
}
print(ans)


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, K) = (input[0], input[1]-1)
let x = readLine()!.characters.split(" ").map{Int(String($0))!}
var ans = 200000000
for i in 0..<N-K {
    let time = min(abs(x[i]), abs(x[i+K])) + abs(x[i]-x[i+K])
    ans = min(time, ans)
}
print(ans)


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, K) = (input[0], input[1])
let x = readLine()!.characters.split(" ").map{Int(String($0))!}
let plus = x.filter{$0>=0}
let minus = x.reverse().filter{$0<0}
var ans = 200000000
for i in max(0, K-minus.count-1)..<min(K, plus.count) {
    var dist = 0
    dist += plus[i]
    if i+1 < K {
        dist -= minus[K-i-2]*2
    }
    ans = min(dist, ans)
}
for i in max(0, K-plus.count-1)..<min(K, minus.count) {
    var dist = 0
    dist -= minus[i]
    if i+1 < K {
        dist += plus[K-i-2]*2
    }
    ans = min(dist, ans)
}
print(ans)


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, K) = (input[0], input[1])
let x = readLine()!.characters.split(" ").map{Int(String($0))!}
let plus = x.filter{$0>=0}
let minus = x.reverse().filter{$0<0}
var ans = 100000000
for i in max(0, K-minus.count-1)..<min(K, plus.count) {
    var dist = 0
    dist += plus[i]
    if i+1 < K {
        dist -= minus[K-i-2]*2
    }
    ans = min(dist, ans)
}
for i in max(0, K-plus.count-1)..<min(K, minus.count) {
    var dist = 0
    dist -= minus[i]
    if i+1 < K {
        dist += plus[K-i-2]*2
    }
    ans = min(dist, ans)
}
print(ans)


const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const solve = (k, xs) => {
  if (xs.length == 1) {
    return xs[0]
  }
  let r = Infinity
  for (var i = 0; i < xs.length - k + 1; i++) {
    let p = xs[i]
    let n = xs[i + k - 1]
    let pa = Math.abs(p)
    let na = Math.abs(n)
    if (n * p > 0) {
      r = Math.min(r, Math.max(na, pa))
    } else {
      let a = pa * 2 + na
      let b = na * 2 + pa

      r = Math.min(r, a, b)
    }
  }
  return r
  // ...
}
const main = (input) => {
  const [head, rest] = input.split("\n")
  const [n, k] = head.split(" ").map(Number)

  return solve(k, rest.split(" ").map(Number))
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

if (process.env.NODE_ENV === "test") {
  // module.exports = (input) => solve(input.trim())
  // main(``)
  // solve(1, [2, 3, 4])
}


import * as fs from 'fs';

const input: string = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] =
  input.split('\n').map(l => l.split(' '));

const [n, k] = args[0].map(x => parseInt(x));
const x = args[1].map(x => parseInt(x));

type Interval = {
  left: number
  right: number
}

const intervals: Interval[] = [];
for (let i = 0; i + k - 1 < n; i++) {
  intervals.push({
    left: x[i],
    right: x[i + k - 1]
  });
}

const time = intervals.map(getTime).reduce((x, y) => Math.min(x, y));

console.log(time);

function getTime(interval: Interval): number {
  const l = interval.left;
  const r = interval.right;
  if (l * r >= 0) {
    return Math.max(Math.abs(l), Math.abs(r))
  } else {
    if (Math.abs(l) < Math.abs(r)) {
      return 2 * Math.abs(l) + Math.abs(r)
    } else {
      return Math.abs(l) + 2 * Math.abs(r)
    }
  }
}


const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const solve = (k, xs) => {
  let loop = xs.length
  if (xs.length == 1) {
    return xs[0]
  }
  let r = Infinity
  for (var i = 0; i < k - 1; i++) {
    let p = xs[i]
    let n = xs[i + k - 1]
    if (n * p > 0) {
      r = Math.min(r, Math.max(Math.abs(n), Math.abs(p)))
    } else {
      let a = Math.abs(p) * 2 + Math.abs(n)
      let b = Math.abs(n) * 2 + Math.abs(p)

      r = Math.min(r, a, b)
    }
  }
  return r
  // ...
}
const main = (input) => {
  const [head, rest] = input.split("\n")
  const [n, k] = head.split(" ").map(Number)

  return solve(k, rest.split(" ").map(Number))
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

if (process.env.NODE_ENV === "test") {
  // module.exports = (input) => solve(input.trim())
  // main(``)
  // solve(1, [2, 3, 4])
}


const solve = (k, xs) => {
  let loop = xs.length
  if (xs.length == 1) {
    return xs[0]
  }
  let r = Infinity
  for (var i = 0; i < k - 1; i++) {
    let p = xs[i]
    let n = xs[i + k - 1]
    if (n * p > 0) {
      r = Math.min(r, Math.max(Math.abs(n), Math.abs(p)))
    } else {
      let a = Math.abs(p) * 2 + Math.abs(n)
      let b = Math.abs(n) * 2 + Math.abs(p)

      r = Math.min(r, a, b)
    }
  }
  return r
  // ...
}
const main = (input) => {
  const [head, rest] = input.split("\n")
  const [n, k] = head.split(" ").map(Number)

  return solve(k, rest.split(" ").map(Number))
}


const solve = (k, xs) => {
  let loop = xs.length
  let r = Infinity
  for (var i = 0; i < k - 1; i++) {
    let p = xs[i]
    let n = xs[i + k - 1]
    if (n * p > 0) {
      r = Math.min(r, Math.max(Math.abs(n), Math.abs(p)))
    } else {
      let a = Math.abs(p) * 2 + Math.abs(n)
      let b = Math.abs(n) * 2 + Math.abs(p)

      r = Math.min(r, a, b)
    }
  }
  return r
  // ...
}
const main = (input) => {
  const [head, rest] = input.split("\n")
  const [n, k] = head.split(" ").map(Number)

  return solve(k, rest.split(" ").map(Number))
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}


# C - Peaks
def main():
    N, M, *HAB = map(int, open(0).read().split())
    H, AB = [0] + HAB[:N], HAB[N:]
    is_good = [False] + [True] * N
    for a, b in zip(*[iter(AB)] * 2):
        if H[a] >= H[b]:
            is_good[b] = False
        if H[b] >= H[a]:
            is_good[a] = False
    print(sum(is_good))

if __name__ == "__main__":
    main()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7

N, M = map(int,input().split())
ok = [1] * N
H = list(map(int,input().split()))
for m in range(M):
    a, b = map(int,input().split())
    a-=1
    b-=1
    if H[a] < H[b]:
        ok[a] = 0
    elif H[a] > H[b]:
        ok[b] = 0
    else:
        ok[a] = 0
        ok[b] = 0

print (sum(ok))


import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]

def main():
    N, M = MI()
    H = LI()
    H.insert(0,0)
    A = [0]*M
    B = [0]*M
    ans = 0
    for i in range(M):
        A[i], B[i]=MI()

    Hnum = [0]*(N+1)
    Hnum[0] = 1

    for i in range(M):
        if H[A[i]]>H[B[i]]:
            Hnum[B[i]]+=1
        elif H[A[i]]<H[B[i]]:
            Hnum[A[i]]+=1
        elif H[A[i]]==H[B[i]]:
            Hnum[A[i]]+=1
            Hnum[B[i]]+=1
    print(Hnum.count(0))

    """
    for i in range(1,N+1):
        ng = 0
        for j in range(M):
            if A[j] == i:
                if H[i]<=H[B[j]]:
                    ng += 1
                    break
            if B[j] == i:
                if H[i]<=H[A[j]]:
                    ng += 1
                    break
        if ng == 0:
            ans += 1
    print(ans)"""

if __name__ == "__main__":
	main()


#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(1,N+1))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b] = 0
    elif H[a-1] < H[b-1]:
        A[a] = 0
    else:
        A[a] = 0
        A[b] = 0
print(N-A.count(0))


#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(N))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b-1] = 0
    elif H[a-1] < H[b-1]:
        A[a-1] = 0
    else:
        A[a-1] = 0
        A[b-1] = 0
print(N-A.count(0))


#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(N))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b-1] = 0
    elif H[a-1] < H[b-1]:
        A[a-1] = 0
    else:
        A[a-1] = 0 and A[b-1] = 0

print(N-A.count(0))


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

public class Main {
	static void solve() {
		int n = ni(), m = ni();
		int h[] = na(n);
		boolean ok[] = new boolean[n];
		fill(ok, true);
		for(int i=0;i<m;i++) {
			int a = ni()-1, b = ni()-1;
			if(h[a]==h[b]) {
				ok[a] = false; ok[b] = false;
			}
			else if(h[a]>h[b]) {
				ok[b]=false;
			}
			else {
				ok[a]=false;
			}
		}
		long ans = 0;
		for(int i=0;i<n;i++) {
			if(ok[i])ans++;
		}
		out.println(ans);
	}

	//constant
	static final long mod = (long) 1e9 + 7;
	static final int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
	static final int[] dx8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final int inf = Integer.MAX_VALUE / 3;
	static final long linf = Long.MAX_VALUE / 3;
	static final double dinf = Double.MAX_VALUE / 3;
	static final double eps = 1e-10;
	static final double pi = Math.PI;
	static StringBuilder sb = new StringBuilder();
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";

	//libraries
	static void reverse(int ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			int t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}

	static void reverse(long ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			long t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}

	static void reverse(double ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			double t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}

	static void reverse(char ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			char t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}

	static String getReverse(String s) {
		char c[] = s.toCharArray();
		reverse(c);
		s = String.valueOf(c);
		return s;
	}

	static <T> void reverse(List<T> ls) {
		int sz = ls.size();
		for (int i = 0; i < sz / 2; i++) {
			T t = ls.get(i);
			ls.set(i, ls.get(sz - 1 - i));
			ls.set(sz - 1 - i, t);
		}
	}

	static <T> void reverse(T[] ar) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			T t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}

	static void sbnl() {//StringBuilderに改行文字をappendする
		sb.append("\n");
	}

	static int lowerBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int upperBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rlowerBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rupperBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int lowerBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int upperBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rlowerBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rupperBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int lowerBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int upperBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rlowerBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rupperBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int lowerBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int upperBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rlowerBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static int rupperBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}

	static <T> int lowerBound(List<T> ls, T x) throws RuntimeException {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) >= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) >= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) >= 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}

	static <T> int upperBound(List<T> ls, T x) throws RuntimeException {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) > 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) > 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) > 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}

	static <T> int rupperBound(List<T> ls, T x) throws RuntimeException {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) < 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) < 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) < 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}

	static <T> int rlowerBound(List<T> ls, T x) {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) <= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) <= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) <= 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}

	static int[] concat(int x, int arr[]) {
		int ret[] = new int[arr.length + 1];
		System.arraycopy(arr, 0, ret, 1, ret.length - 1);
		ret[0] = x;
		return ret;
	}

	static int[] concat(int arr[], int x) {
		int ret[] = new int[arr.length + 1];
		System.arraycopy(arr, 0, ret, 0, ret.length - 1);
		ret[ret.length - 1] = x;
		return ret;
	}

	static long[] concat(long x, long arr[]) {
		long ret[] = new long[arr.length + 1];
		System.arraycopy(arr, 0, ret, 1, ret.length - 1);
		ret[0] = x;
		return ret;
	}

	static long[] concat(long arr[], long x) {
		long ret[] = new long[arr.length + 1];
		System.arraycopy(arr, 0, ret, 0, ret.length - 1);
		ret[ret.length - 1] = x;
		return ret;
	}

	static int max(int x, int y) {
		return Math.max(x, y);
	}

	static int min(int x, int y) {
		return Math.min(x, y);
	}

	static int max(int x, int y, int z) {
		x = Math.max(x, y);
		x = Math.max(x, z);
		return x;
	}

	static int min(int x, int y, int z) {
		x = Math.min(x, y);
		x = Math.min(x, z);
		return x;
	}

	static long max(long x, long y) {
		return Math.max(x, y);
	}

	static long min(long x, long y) {
		return Math.min(x, y);
	}

	static long max(long x, long y, long z) {
		x = Math.max(x, y);
		x = Math.max(x, z);
		return x;
	}

	static long min(long x, long y, long z) {
		x = Math.min(x, y);
		x = Math.min(x, z);
		return x;
	}

	static double max(double x, double y) {
		return Math.max(x, y);
	}

	static double min(double x, double y) {
		return Math.min(x, y);
	}

	static double max(double x, double y, double z) {
		x = Math.max(x, y);
		x = Math.max(x, z);
		return x;
	}

	static double min(double x, double y, double z) {
		x = Math.min(x, y);
		x = Math.min(x, z);
		return x;
	}

	static void sort(int[] ar) {
		Arrays.sort(ar);
	}

	static void sort(long[] ar) {
		Arrays.sort(ar);
	}

	static void sort(double[] ar) {
		Arrays.sort(ar);
	}

	static void sort(char[] ar) {
		Arrays.sort(ar);
	}

	static void rsort(int[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			int tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}

	static void rsort(long[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			long tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}

	static void rsort(double[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			double tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}

	static void rsort(char[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			char tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}

	static void fill(int arr[], int x) {
		Arrays.fill(arr, x);
	}

	static void fill(long arr[], long x) {
		Arrays.fill(arr, x);
	}

	static void fill(boolean arr[], boolean x) {
		Arrays.fill(arr, x);
	}

	static void fill(double arr[], double x) {
		Arrays.fill(arr, x);
	}

	static void fill(int arr[][], int x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}

	static void fill(long arr[][], long x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}

	static void fill(double arr[][], double x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}

	static void fill(boolean arr[][], boolean x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}

	//MOD culc
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}

	public static void main(String[] args) throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	//input
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;

	private static 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 static boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

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

	@SuppressWarnings("unused")
	private static double nd() {
		return Double.parseDouble(ns());
	}

	@SuppressWarnings("unused")
	private static char nc() {
		return (char) skip();
	}

	private static String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private static 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);
	}

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

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

	@SuppressWarnings("unused")
	private static long[] nla(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

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

	@SuppressWarnings("unused")
	private static 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();
		}
	}

}


public final class Main {
  private static void execute(final IO io) throws Exception {
    int n = io.nextInt();
    int m = io.nextInt();
    long[] h = io.nextLong(n);
    boolean[] bad = new boolean[n];
    int result = n;
    for (int i = 0; i < m; i++) {
      int a = io.nextInt() - 1;
      int b = io.nextInt() - 1;
      if (h[a] <= h[b]) {
        if (!bad[a]) {
          bad[a] = true;
          result--;
        }
      }
      if (h[a] >= h[b]){
        if (!bad[b]) {
          bad[b] = true;
          result--;
        }
      }
    }
    io.println(result);
  }

  public static void main(final String[] args) throws Exception {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  }

  public static final class M {
    public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    }

    public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    }

    public static int min(final int a, final int b) {
      return a > b ? b : a;
    }

    public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    }
  }

  public static final class MC {
    private final int mod;
    public MC(final int mod) {
      this.mod = mod;
    }

    public long mod(long x) {
      x %= mod;
      if (x < 0) {
        x += mod;
      }
      return x;
    }

    public long add(final long a, final long b) {
      return mod(a + b);
    }

    public long mul(final long a, final long b) {
      return mod(a * b);
    }

    public long div(final long numerator, final long denominator) {
      return mod(numerator * inverse(denominator));
    }

    public long power(long base, long exp) {
      long ret = 1;
      base %= mod;
      while (exp > 0) {
        if ((exp & 1) == 1) {
          ret = mul(ret, base);
        }
        base = mul(base, base);
        exp >>= 1;
      }
      return ret;
    }

    public long inverse(final long x) {
      return power(x, mod - 2);
    }

    public long factorial(final int n) {
      return product(1, n);
    }

    public long product(final int start, final int end) {
      long result = 1;
      for (int i = start; i <= end; i++) {
        result *= i;
        result %= mod;
      }
      return result;
    }

    public long combination(final int n, int r) {
      if (r > n) {
        return 0;
      }
      return div(product(n - r + 1, n), factorial(r));
    }
  }

  public static final class IO implements AutoCloseable {
    private final java.io.InputStream in;
    private final java.io.BufferedOutputStream out;
    private static final int BUFFER_SIZE = 1 << 16;
    private final byte[] buf = new byte[BUFFER_SIZE];
    private int pos = 0;
    private int end = 0;
    public IO(final java.io.InputStream in, final java.io.OutputStream out) throws java.io.IOException {
      this.in = in;
      this.out = new java.io.BufferedOutputStream(out);
    }

    @Override
    public void close() throws java.io.IOException {
      out.close();
    }

    private int fetchByte() throws java.io.IOException {
      if (pos >= end) {
        pos = 0;
        end = in.read(buf);
        if (end <= 0) {
          return -1;
        }
      }
      return buf[pos++];
    }

    public String nextString() throws java.io.IOException {
      int c;
      for (c = fetchByte(); c <= ' '; c = fetchByte()) {
      }
      final StringBuilder sb = new StringBuilder();
      for (; c > ' '; c = fetchByte()) {
        sb.append((char) c);
      }
      return sb.toString();
    }

    public String[] nextString(final int n) throws java.io.IOException {
      final String[] result = new String[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextString();
      }
      return result;
    }

    public int nextInt() throws java.io.IOException {
      int val = 0;
      int c;
      for (c = fetchByte(); c <= ' '; c = fetchByte()) {
      }
      boolean neg = c == '-';
      if (c == '-' || c == '+') {
        c = fetchByte();
      }
      for (; c >= '0' && c <= '9'; c = fetchByte()) {
        val = (val << 3) + (val << 1) + (c & 15);
      }
      return neg ? -val : val;
    }

    public int[] nextInt(final int n) throws java.io.IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    }

    public long nextLong() throws java.io.IOException {
      long val = 0;
      int c;
      for (c = fetchByte(); c <= ' '; c = fetchByte()) {
      }
      boolean neg = c == '-';
      if (c == '-' || c == '+') {
        c = fetchByte();
      }
      for (; c >= '0' && c <= '9'; c = fetchByte()) {
        val = (val << 3) + (val << 1) + (c & 15);
      }
      return neg ? -val : val;
    }

    public long[] nextLong(final int n) throws java.io.IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    }

    public void print(final Object a) throws java.io.IOException {
      out.write(a.toString().getBytes());
    }

    private static final byte[] SP = new byte[] { 0x20 };
    public void printsp(final Object a) throws java.io.IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    }

    private static final byte[] CRLF = System.lineSeparator().getBytes();
    public void println() throws java.io.IOException {
      out.write(CRLF);
    }

    public void println(final Object a) throws java.io.IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    }

    public void printaln(final int[] a) throws java.io.IOException {
      for (int i = 0, n = a.length; i < n; i++) {
        out.write(Integer.toString(a[i]).getBytes());
        out.write(CRLF);
      }
    }

    public void printasp(final int[] a) throws java.io.IOException {
      for (int i = 0, n = a.length; i < n; i++) {
        out.write(Integer.toString(a[i]).getBytes());
        out.write(SP);
      }
    }

    public void printaln(final long[] a) throws java.io.IOException {
      for (int i = 0, n = a.length; i < n; i++) {
        out.write(Long.toString(a[i]).getBytes());
        out.write(CRLF);
      }
    }

    public void printasp(final long[] a) throws java.io.IOException {
      for (int i = 0, n = a.length; i < n; i++) {
        out.write(Long.toString(a[i]).getBytes());
        out.write(SP);
      }
    }

    public void printaln(final Object[] a) throws java.io.IOException {
      for (int i = 0, n = a.length; i < n; i++) {
        out.write(a[i].toString().getBytes());
        out.write(CRLF);
      }
    }

    public void printasp(final Object[] a) throws java.io.IOException {
      for (int i = 0, n = a.length; i < n; i++) {
        out.write(a[i].toString().getBytes());
        out.write(SP);
      }
    }

    public void flush() throws java.io.IOException {
      out.flush();
    }
  }
}


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

import static java.lang.Math.*;

public class Main implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		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 String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int[] nextArray(int n)
		{
			int arr[] = new int[n];
			int i;
			for(i=0;i<n;i++)
			{
				arr[i] = nextInt();
			}
			return arr;
		}
		public int nextInt()
		{
			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 long nextLong()
		{
			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 double nextDouble()
		{
			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, nextInt());
				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, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			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 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 int[] nextIntArray(int n)
		{
			int i;
			int arr[] = new int[n+1];
			for(i=1;i<=n;i++)
			{
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n)
		{
			int i;
			long arr[] = new long[n];
			for(i=0;i<n;i++)
			{
				arr[i] = nextLong();
			}
			return arr;
		}

		public double[] nextDoubleArray(int n)
		{
			int i;
			double arr[] = new double[n];
			for(i=0;i<n;i++)
			{
				arr[i] = nextDouble();
			}
			return arr;
		}

		public Integer[] IntegerArray(int n)
		{
			int i;
			Integer arr[] = new Integer[n];
			for(i=0;i<n;i++)
			{
				arr[i] = nextInt();
			}
			return arr;
		}

		public Long[] LongArray(int n)
		{
			int i;
			Long arr[] = new Long[n];
			for(i=0;i<n;i++)
			{
				arr[i] = nextLong();
			}
			return arr;
		}

		public Double[] DoubleArray(int n)
		{
			int i;
			Double arr[] = new Double[n];
			for(i=0;i<n;i++)
			{
				arr[i] = nextDouble();
			}
			return arr;
		}

		public ArrayList<ArrayList<Integer>> getGraph(int n,int m)
		{
			ArrayList<ArrayList<Integer>> g =new ArrayList<>();
			int i;
			for(i=0;i<=n;i++)
			{
				g.add(new ArrayList<>());
			}
			for(i=0;i<m;i++)
			{
				int x = nextInt();
				int y = nextInt();
				g.get(x).add(y);
				g.get(y).add(x);
			}
			return g;
		}

		public ArrayList<ArrayList<Integer>> getTree(int n)
		{
			ArrayList<ArrayList<Integer>> g =new ArrayList<>();
			int i;
			for(i=0;i<=n;i++)
			{
				g.add(new ArrayList<>());
			}
			for(i=0;i<n-1;i++)
			{
				int x = nextInt();
				int y = nextInt();
				g.get(x).add(y);
				g.get(y).add(x);
			}
			return g;
		}
	}

	public static int maxInt(int arr[])
	{
		int max = Integer.MIN_VALUE;
		for(int i : arr)
		{
			max = Math.max(i,max);
		}
		return max;
	}

	public static int minInt(int arr[])
	{
		int min = Integer.MAX_VALUE;
		for(int i : arr)
		{
			min = Math.min(i,min);
		}
		return min;
	}

	public static long maxLong(long arr[])
	{
		long max = Long.MIN_VALUE;
		for(long i : arr)
		{
			max = Math.max(i,max);
		}
		return max;
	}

	public static long minLong(long arr[])
	{
		long min = Long.MAX_VALUE;
		for(long i : arr)
		{
			min = Math.min(i,min);
		}
		return min;
	}

	public static double maxDouble(double arr[])
	{
		double max = Double.MIN_VALUE;
		for(double i : arr)
		{
			max = Math.max(i,max);
		}
		return max;
	}

	public static double minDouble(double arr[])
	{
		double min = Double.MAX_VALUE;
		for(double i : arr)
		{
			min = Math.min(i,min);
		}
		return min;
	}

	void merge(int arr[], int l, int m, int r)
	{
		int n1 = m - l + 1;
		int n2 = r - m;

		int L[] = new int [n1];
		int R[] = new int [n2];

		for (int i=0; i<n1; ++i)
		    L[i] = arr[l + i];
		for (int j=0; j<n2; ++j)
		    R[j] = arr[m + 1+ j];

		int i = 0, j = 0;

		int k = l;
		while (i < n1 && j < n2)
		{
		    if (L[i] <= R[j])
		    {
			arr[k] = L[i];
			i++;
		    }
		    else
		    {
			arr[k] = R[j];
			j++;
		    }
		    k++;
		}

		while (i < n1)
		{
		    arr[k] = L[i];
		    i++;
		    k++;
		}

		while (j < n2)
		{
		    arr[k] = R[j];
		    j++;
		    k++;
		}
	}

	void sort(int arr[], int l, int r)
	{
		if (l < r)
		{
			int m = (l+r)/2;
			sort(arr, l, m);
			sort(arr , m+1, r);
			merge(arr, l, m, r);
		}
	}

	static class Pair
	{
		int x,y;
		public Pair(int f,int s)
		{
			this.x = y;
			this.x = y;
		}
		public static Comparator<Pair> sortX = new Comparator<Pair>(){
			public int compare(Pair p1,Pair p2)
			{
				if(p1.x==p2.x)
				{
					return p1.y-p2.y;
				}
				return p1.x-p2.x;
			}
		};

		public static Comparator<Pair> sortY = new Comparator<Pair>(){
			public int compare(Pair p1,Pair p2)
			{
				if(p1.y==p2.y)
				{
					return p1.x-p2.x;
				}
				return p1.y-p2.y;
			}
		};
	}

	static class DSU
	{
		public static int rank[],parent[];
		int n;
		HashMap<Integer,Integer> map = new HashMap<>();

		public DSU(int n)
		{
			rank = new int[n+1];
			parent = new int[n+1];
			this.n = n;
			makeSet(n);
		}

		public void makeSet(int n)
		{
			for(int i=1;i<=n;i++)
			{
				parent[i] = i;
				map.put(i,1);
			}
		}

		public static int find(int x)
		{
			if(parent[x]!=x)
			{
				parent[x] = find(parent[x]);
			}
			return parent[x];
		}

		public void union(int x,int y)
		{
			int xRoot = find(x);
			int yRoot = find(y);

			if(xRoot==yRoot)
			{
				return;
			}

			if(rank[xRoot] < rank[yRoot])
			{
				parent[xRoot] = yRoot;
				map.put(yRoot,map.getOrDefault(yRoot,1)+map.getOrDefault(xRoot,1));
				if(map.getOrDefault(xRoot,0)!=0)
				{
					map.remove(xRoot);
				}
			}
			else if(rank[yRoot] < rank[xRoot])
			{
				parent[yRoot] = xRoot;
				map.put(xRoot,map.getOrDefault(xRoot,1) + map.getOrDefault(yRoot,1));
				if(map.getOrDefault(yRoot,0)!=0)
				{
					map.remove(yRoot);
				}
			}
			else
			{
				parent[yRoot] = xRoot;
				rank[xRoot] = rank[xRoot] + 1;
				map.put(xRoot,map.getOrDefault(xRoot,1)+map.getOrDefault(yRoot,1));
				if(map.getOrDefault(yRoot,0)!=0)
				{
					map.remove(yRoot);
				}
			}
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Main(),"Main",1<<27).start();
	}

	public void run()
	{
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n = in.nextInt();
		int m = in.nextInt();
		int hash[] = new int[n+1];
		int arr[] = in.nextIntArray(n);
		int i,j,k;
		for(i=0;i<m;i++)
		{
			int x = in.nextInt();
			int y = in.nextInt();
			hash[x] = Math.max(hash[x],arr[y]);
			hash[y] = Math.max(hash[y],arr[x]);
		}
		int count = 0;
		for(i=1;i<=n;i++)
		{
			if(arr[i]>hash[i])
			{
				count++;
			}
		}
		w.println(count);
		w.flush();
		w.close();
	}
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }

	//フィールド
    Scanner sc;
    int N;
    int M;
    int[] H;
    int[] A;
    int[] B;

    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.M = sc.nextInt();
        this.H = new int[N];
        this.A = new int[N];
        this.B = new int[N];
        for (int i = 0; i < N; i++) {
        	this.H[i] = sc.nextInt();
        }
        for (int i = 0; i < M; i++) {
        	this.A[i] = sc.nextInt();
        	this.B[i] = sc.nextInt();
        }
    }

    //解答処理
    private int solve() {
        int count = 0;
        int[] m = new int[N];

        for (int i = 0; i < M; i++) {
        	m[A[i]-1] = Math.max(m[A[i]-1], H[B[i]-1]);
        	m[B[i]-1] = Math.max(m[B[i]-1], H[A[i]]-1);
        }

        for (int i = 0; i < N; i++) {
        	if (m[i] < H[i]) {
        		count++;
        	}
        }

        return count;
    }

    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		// 4 3
		// 1 2 3 4
		// 1 3
		// 2 3
		// 2 4
		Set<Integer> ans = new HashSet<>();
		for (int i = 0; i < n; i++) {
			ans.add(i + 1);
		}
		int[] heights = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			heights[i] = sc.nextInt();
		}

		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (heights[b] > a) {
				ans.remove(a);
			}
			if (heights[a] > b) {
				ans.remove(b);
			}
		}
		System.out.println(ans.size());
	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		// 4 3
		// 1 2 3 4
		// 1 3
		// 2 3
		// 2 4
		Map<Integer, PriorityQueue<Integer>> graph = new HashMap<>();
		for (int i = 0; i < n; i++) {
			graph.put(i + 1, new PriorityQueue<>(m, Collections.reverseOrder()));
		}
		int[] heights = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			heights[i] = sc.nextInt();
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			graph.get(a).add(heights[b]);
			graph.get(b).add(heights[a]);
		}
		int ans = 0;
		for (Map.Entry<Integer, PriorityQueue<Integer>> entry : graph.entrySet()) {
			int node = entry.getKey();
			PriorityQueue<Integer> maxHeap = entry.getValue();
			if (maxHeap.isEmpty() || maxHeap.peek() < heights[node]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

int H[100001];
bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N = getint(), M = getint();
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}


#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

//同じコードでそんなにばらつくんですか

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

int H[100001];
bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N = getint(), M = getint();
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}


#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

//同じコードでそんなにばらつくんですか

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N = getint(), M = getint();
	int H[100001];
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
  int N,M;cin>>N>>M;
  vector<int> H(N+1,);
  for(int i=1;i<=N;i++) cin>>H.at(i);
  vector<bool> good(N+1,true);
  int count=N;
  for(int j=0;j<M;j++){
    int a,b;cin>>a>>b;
    if(H.at(a)>=H.at(b) && good.at(b)){
      good.at(b)=false;
      count--;
    }
    if(H.at(a)<=H.at(b) && good.at(a)){
      good.at(a)=false;
      count--;
    }
  }
  cout<<count<<endl;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// #define N 100010

// int main(){
//     int n, m, h[N], ma[N];
//     cin >> n >> m;
//     rep(i,n){
//         cin >> h[i];
//         ma[i] = 0;
//     }
//     rep(i,m){
//         int a, b;
//         cin >> a >> b;
//         ma[a-1] = max(ma[a-1], h[b-1]);
//         ma[b-1] = max(ma[b-1], h[a-1]);
//     }
//     int ans = 0;
//     rep(i,n) {
//         if(h[i] > ma[i]) ans++;
//     }
//     cout << ans << endl;
//     return 0;
// }

int main(){
    int n, m;
    cin  >> n >> m;
    vector<int> h(n);
    vector<bool> ok(n, true);
    rep(i,m) cin >> h[i];
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        if(h[a-1] <= h[b-1]) ok[a-1] = false;
        if(h[b-1] <= h[a-1]) ok[b-1] = false;
    }
    int ans = 0;
    rep(i,n) if(ok[i]) ans++;
    cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define N 100010

int main(){
    int n, m, h[N], ma[N];
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        cin >> h[i];
        ma[i] = 0;
    }
    rep(i,m){
        int a, b;
        cin >> a >> b;
        ma[a] = max(ma[a], h[b]);
        ma[b] = max(ma[b], h[a]);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += h[i] > ma[i];
    }
    cout << ans << endl;
    return 0;
}


#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char stdibuf[2500015];
uint32_t stdibufl;

bool arr[101];

uint32_t nextpint(void){ char c=stdibuf[stdibufl++]; while(c<'0'||'9'<c) c=stdibuf[stdibufl++]; uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=stdibuf[stdibufl++]; } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

uint32_t h[100000];
uint8_t is[100000];

int main(void){
	read(0, stdibuf, 2500014);
	uint32_t n=nextpint();
	uint32_t m=nextpint();
	for(uint32_t i=0; i<n; i++){
		h[i]=nextpint();
	}
	for(uint32_t i=0; i<m; i++){
		uint32_t a=nextpint()-1;
		uint32_t b=nextpint()-1;
		if(h[a]<=h[b]) is[a]=1;
		if(h[a]>=h[b]) is[b]=1;
	}
	uint32_t ans=0;
	for(uint32_t i=0; i<n; i++){
		ans+=is[i];
	}
	printint(n-ans);
}


#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

bool arr[101];

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

uint32_t h[100000];
bool is[100000];

int main(void){
	uint32_t n=nextpint();
	uint32_t m=nextpint();
	for(uint32_t i=0; i<n; i++){
		h[i]=nextpint();
	}
	for(uint32_t i=0; i<m; i++){
		uint32_t a=nextpint()-1;
		uint32_t b=nextpint()-1;
		if(h[a]>h[b]){
			is[b]=true;
		}else if(h[a]<h[b]){
			is[a]=true;
		}else{
			is[a]=true;
			is[b]=true;
		}
	}
	uint32_t ans=0;
	for(uint32_t i=0; i<n; i++){
		if(!is[i]) ans++;
	}
	printint(ans);
}


#include <stdio.h>

int main(void)
{
    int n=0,m=0,a=0,b=0,count=0;
    int H[100000]={},flag[100000]={};
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&H[i]);
    }
    for(int i=0;i<m;i++){
        scanf("%d %d",&a,&b);
        if(H[a-1]>H[b-1]){
            flag[a-1]=1;
            flag[b-1]=-1;
        } else if(H[a-1]==H[b-1]){
            flag[a-1]=-1;
            flag[b-1]=-1;
        } else {
            flag[b-1]=1;
            flag[a-1]=-1;
        }
    }
    for(int i=0;i<n;i++){
        if(flag[i]>=0) count+=1;
    }

    printf("%d\n",count);
    return 0;
}


#include<stdio.h>
int main(){
	int n,m,i,a,b,ans;
	scanf("%d %d",&n,&m);
	int h[n];
	int count[n];
	for(i=1;i<=n;i++){
	scanf("%d",&h[i]);
	count[i]=1;
	}
	for(i=1;i<=m;i++){
		scanf("%d %d",&a,&b);
		if(h[a]>=h[b]){
			count[b]=0;
		}
		if(h[a]<=h[b])
		count[a]=0;
	}
	int count=0;
	for(i=1,ans=0;i<=n;i++){
		if(count[i]==1)
		ans++;
	}
	printf("%d",ans);
}


#include<stdio.h>
int main(){
	int n,m,a,b,i,ans;
	scanf("%d %d",&n,&m);
	int h[n+1],count[n+1];
	for(i=1;i<=n;i++){
	scanf("%d",&h[i]);
	count[i]=1;
	}
	for(i=1;i<=m;i++){
		scanf("%d %d",&a,&b);
		if(h[a]>=h[b]){
			count[b]=0;
		}
		if(h[a]<=h[b])
		count[a]=0;
    }
	for(int i=1;i<=n;i++){
		if(count[i]==1)
		ans++;
	}
	printf("%d",ans);
}


"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/), cid = 0;
function next(a) { return a ? cin[cid++] : +cin[cid++]; }
function nexts(n, a) { return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a); }
function nextm(h, w, a) { var r = [], i = 0; if (a) for (; i < h; i++)r.push(cin.slice(cid, cid += w)); else for (; i < h; i++)r.push(cin.slice(cid, cid += w).map(a => +a)); return r; }
function xArray(v) { var a = arguments, l = a.length, r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})"; while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")"; return eval(r); }

var myOut = main();
if (myOut !== undefined) console.log(myOut);

function main() {
    //console.log(cin);
    cin = cin.map(i => +i);
    let n = cin.shift();
    let m = cin.shift();
    let h = cin.slice(0, n); cin = cin.slice(n);
    h.unshift(0);
    let a;
    let b;
    let good = Array(n + 1).fill(1);
    good[0] = 0;
    for (let i = 0; i < m; i++) {
        // A.push(cin[2 * i]);
        // B.push(cin[2 * i + 1]);
        a = cin[2 * i];
        b = cin[2 * i + 1];
        if (h[a] >= h[b]) {
            good[b] = 0;
        }
        if (h[b] >= h[a]) {
            good[a] = 0;
        }
    }
    // console.log("n", n);
    // console.log("m", m);
    // console.log("h", h);
    // console.log("A", A);
    // console.log("B", B);
    let ans = 0;
    good.forEach(i => { ans += i; });

    return ans;
}


function main(input) {
  const lines = input.trim().split("\n");
  const [N, M] = lines.shift().split(' ').map(Number);
  const h = lines.shift().split(' ').map(Number);

  const isGood = Array(N).fill(true);
  lines.forEach(l => {
    const [a, b] = l.split(' ');
    if (h[a-1] > h[b-1]) {
      isGood[b-1] = false;
    } else if (h[a-1] < h[b-1]) {
      isGood[a-1] = false;
    } else {
      isGood[a-1] = false;
      isGood[b-1] = false;
    }
  });
  const res = isGood.filter(g => g).length;

  console.log(res);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(_input) {
    var lines = _input.split("\n");
    var first = lines.shift().split(' ');
    var dai = first[0] * 1;
    var road = first[1] * 1;
    var heights = lines.shift().split(' ').map((item) => item*1);
    var r = Array(dai).fill(true);

    for (var i = 0; i < road; i++) {
        var s = lines[i].split(' ');
        var f = s[0]*1 - 1;
        var n = s[1]*1 - 1;

        if (heights[f] <= heights[n]) r[f] = false;
        if (heights[n] <= heights[f]) r[n] = false;
    }

    var count = 0;
    for (var i = 0; i < dai; i++) {
        if (r[i]) count++;
    }

    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


const main = (input) => {
  input = input.trim().split('\n')
  const [n,] = input[0].split(' ').map(Number)
  const [, ...arr] = input

  const lighthouse = [0, ...input[1].split(' ').map(BigInt)]
  const ans = [false, ...new Array(n).fill(true)]

  for (let i=0; i<arr.length; i++) {
    const [a, b] = arr[i].split(' ').map(Number)

    if (lighthouse[a] >= lighthouse[b]) ans[b] = false
    if (lighthouse[a] <= lighthouse[b]) ans[a] = false
  }

  let count = 0
  for (let i=1; i<ans.length; i++)
    if (ans[i]) count++

  return console.log(count)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))


const main = (input) => {
  input = input.trim().split('\n')
  const [n, m] = input[0].split(' ').map(Number)
  const [, ...arr] = input

  const lighthouse = [0, ...input[1].split(' ').map(Number)]
  const ans = [false, ...new Array(n).fill(true)]

  for (let i=0; i<arr.length; i++) {
    const [a, b] = arr[i].split(' ').map(Number)

    if (lighthouse[a] >= lighthouse[b]) ans[b] = false
    if (lighthouse[a] <= lighthouse[b]) ans[a] = false
  }

  let count = 0
  for (let i=1; i<ans.length; i++)
    if (ans[i]) count++

  return console.log(count)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	h := make([]int, n)
	good := make([]bool, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
		good[i] = true
	}
	for i := 0; i < m; i++ {
		ai := nextInt() - 1
		bi := nextInt() - 1
		if h[ai] > h[bi] {
			good[bi] = false
		} else if h[ai] < h[bi] {
			good[ai] = false
		} else {
			good[ai] = false
			good[bi] = false
		}
	}
	ans := 0
	for i := 0; i < n; i++ {
		if good[i] {
			ans++
		}
	}
	fmt.Println(ans)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)
	N := nextInt()
	M := nextInt()
	H := make([]int, N)
	heightPeakEnableds := make([]bool, N)
	for i := 0; i < N; i++ {
		H[i] = nextInt()
		heightPeakEnableds[i] = true
	}

	for i := 0; i < M; i++ {
		a := nextInt()
		b := nextInt()
		if H[a-1] > H[b-1] {
			heightPeakEnableds[b-1] = false
		} else if H[a-1] < H[b-1] {
			heightPeakEnableds[a-1] = false
		} else {
			heightPeakEnableds[b-1] = false
			heightPeakEnableds[a-1] = false
		}
	}

	r := 0
	for _, heightPeakEnabled := range heightPeakEnableds {
		if heightPeakEnabled {
			r++
		}
	}
	fmt.Println(r)
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	m, _ := strconv.Atoi(input())
	h := make([]int, n)
	a := make([]int, m)
	b := make([]int, m)
	for i := 0; i < n; i++ {
		h[i], _ = strconv.Atoi(input())
	}
	for i := 0; i < m; i++ {
		a[i], _ = strconv.Atoi(input())
		b[i], _ = strconv.Atoi(input())
	}

	isHigh := make([]bool, n)
	for i := 0; i < n; i++ {
		isHigh[i] = true
	}
	for i := 0; i < m; i++ {
		ai, bi := a[i], b[i]
		ai--
		bi--
		if h[ai] == h[bi] {
			isHigh[ai] = false
			isHigh[bi] = false
		} else if h[ai] < h[bi] {
			isHigh[ai] = false
		} else {
			isHigh[bi] = false
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		if isHigh[i] {
			ans++
		}
	}
	fmt.Println(ans)
}