#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

fn merge<T, F>(xs: Vec<T>, ys: Vec<T>, compare: F) -> Vec<T>
where
    F: Fn(&T, &T) -> std::cmp::Ordering,
{
    let mut acc: Vec<T> = Vec::with_capacity(xs.len() + ys.len());
    let mut xi = xs.into_iter();
    let mut yi = ys.into_iter();
    let mut x = xi.next();
    let mut y = yi.next();

    loop {
        let i;

        // match (&x, &y) {
        //     (&None, &None) => { break; },
        //     (&None, &Some(ref y_)) => { acc.push(y_); },
        //     (&Some(x_), &None) => { acc.push(x_); },
        //     (&Some(x_), &Some(y_)) => {
        //         match compare(&x_, &y_) {
        //             Ordering::Greater => {
        //                 acc.push(y_);
        //                 y = yi.next();
        //             },
        //             _ => {
        //                 acc.push(x_);
        //                 x = xi.next();
        //             },
        //         }
        //     },
        // }
        match (&x, &y) {
            (&None, &None) => { break; },
            (&None, &Some(_)) => { i = 1; },
            (&Some(_), &None) => { i = 0; },
            (&Some(ref x_), &Some(ref y_)) => {
                match compare(&x_, &y_) {
                    Ordering::Greater => {
                        i = 1;
                    },
                    _ => {
                        i = 0;
                    },
                }
            },
        }

        match i {
            0 => {
                acc.push(x.unwrap());
                x = xi.next();
            },
            1 => {
                acc.push(y.unwrap());
                y = yi.next();
            },
            _ => unreachable!(),
        }
    };

    acc
}


fn main() {
    let (n, mut an, mut xs) = {
        input! {
            n: usize,
            m: usize,
            an: [u64; n],
            xs: [(usize, u64); m],
        }
        (n, an, xs)
    };

    an.sort_by(|a1, a2| a2.cmp(&a1));
    xs.sort_by(|x1, x2| x2.1.cmp(&x1.1));
    let ys = xs.into_iter().flat_map(|(b, c)| vec![c; b]).take(n).vec();

    let zs = merge(an, ys, |a, b| b.cmp(&a));

    let ans = zs.iter().take(n).fold(0, |a, x| a + x);
    println!("{}", ans);
}


Measured memory_bytes: 12408