On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.

The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as v_{i}. The child spend v_{f}_1 + v_{f}_2 + ... + v_{f}_{k} energy for removing part i where f_1, f_2, ..., f_{k} are the parts that are directly connected to the i-th and haven't been removed.

Help the child to find out, what is the minimum total energy he should spend to remove all n parts.


-----Input-----

The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v_1, v_2, ..., v_{n} (0 ≤ v_{i} ≤ 10^5). Then followed m lines, each line contains two integers x_{i} and y_{i}, representing a rope from part x_{i} to part y_{i} (1 ≤ x_{i}, y_{i} ≤ n; x_{i} ≠ y_{i}).

Consider all the parts are numbered from 1 to n.


-----Output-----

Output the minimum total energy the child should spend to remove all n parts of the toy.


-----Examples-----
Input
4 3
10 20 30 40
1 4
1 2
2 3

Output
40

Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4

Output
400

Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4

Output
160



-----Note-----

One of the optimal sequence of actions in the first sample is:  First, remove part 3, cost of the action is 20.  Then, remove part 2, cost of the action is 10.  Next, remove part 4, cost of the action is 10.  At last, remove part 1, cost of the action is 0. 

So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.

In the second sample, the child will spend 400 no matter in what order he will remove the parts.

Difficulty: MEDIUM

Solutions:
def solve(n, m, energy, link):
	total = 0
	for (x, y) in link:
		total += min(energy[x - 1], energy[y - 1])
	return total
(n, m) = list(map(int, input().split()))
ener = list(map(int, input().split()))
mat = []
for _ in range(m):
	mat.append(list(map(int, input().split())))
print(solve(n, m, ener, mat))


(n, m) = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
ans = 0
for _ in range(m):
	(x, y) = [int(x) for x in input().split()]
	ans += min(v[x - 1], v[y - 1])
print(ans)


def byF(p):
	return p[0]

def byS(p):
	return p[1]

def getOrder(ls):
	pairs = [(i, ls[i]) for i in range(len(ls))]
	pairs.sort(key=byS)
	return list(map(byF, pairs))
(n, m) = map(int, input().split())
vs = list(map(int, input().split()))
edges = [[] for x in range(n)]
delted = [False] * n
for _ in range(m):
	(i, j) = map(int, input().split())
	edges[i - 1].append(j - 1)
	edges[j - 1].append(i - 1)
order = getOrder(vs)
order = order[::-1]
res = 0
for curr in order:
	for neigh in edges[curr]:
		if not delted[neigh]:
			res += vs[neigh]
	delted[curr] = True
print(res)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, eg) = lst()
	a = lst()
	ans = 0
	for i in range(eg):
		(u, v) = lst()
		ans += min(a[u - 1], a[v - 1])
	print(ans)


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
ans = 0
for i in range(m):
	(a, b) = map(int, input().split())
	ans += min(f[a - 1], f[b - 1])
print(ans)


(n, m) = map(int, input().split())
v = list(map(int, input().split()))
V = list(v)
Cost = [0] * n
Children = []
for i in range(n):
	V[i] = (v[i], i)
	Children.append([])
V.sort(reverse=True)
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	Children[x].append(y)
	Children[y].append(x)
	Cost[x] += v[y]
	Cost[y] += v[x]
ans = 0
for i in range(n):
	z = V[i][0]
	x = V[i][1]
	ans += Cost[x]
	for child in Children[x]:
		Cost[child] -= z
print(ans)


a = list(map(int, input().split()))
energy = list(map(int, input().split()))
nodes = []
for i in range(a[1]):
	tmp = list(map(int, input().split()))
	nodes.append((tmp[0], tmp[1]))
summ = 0
while True:
	tmp = []
	maxx = max(energy)
	andis = energy.index(maxx)
	energy[andis] = -1
	andis += 1
	for item in nodes:
		if andis not in item:
			tmp.append(item)
		elif item[0] != andis:
			summ += energy[item[0] - 1]
		else:
			summ += energy[item[1] - 1]
	nodes = tmp
	if len(nodes) == 0:
		print(summ)
		break


(n, m) = input().split()
v = list(map(int, input().split()))
ans = 0
for _ in range(int(m)):
	ans += v[min(map(int, input().split()), key=lambda x: v[x - 1]) - 1]
print(ans)


import sys
import itertools
import math
import collections
from collections import Counter

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
(n, m) = mi()
p = [0] * n
g = [[] for i in range(n)]
w = li()
for i in range(n):
	w[i] = [w[i], i]
for i in range(m):
	(u, v) = mi()
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
	p[u - 1] += w[v - 1][0]
	p[v - 1] += w[u - 1][0]
w.sort(reverse=True)
res = 0
for i in range(n - 1):
	res += p[w[i][1]]
	for j in g[w[i][1]]:
		p[j] -= w[i][0]
print(res)


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from math import sqrt, ceil, floor, factorial, gcd, log2, log10
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
(n, m) = zzz()
arr = zzz()
ans = 0
for i in range(m):
	(x, y) = zzz()
	x -= 1
	y -= 1
	ans += min(arr[x], arr[y])
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
adl = [[] for i in range(n)]
sum1 = [0 for i in range(n)]
aa = [(a[i], i) for i in range(n)]
for i in range(m):
	(b, c) = map(int, input().split())
	adl[b - 1].append(c - 1)
	adl[c - 1].append(b - 1)
	sum1[b - 1] += a[c - 1]
	sum1[c - 1] += a[b - 1]
ans = 0
aa.sort()
aa.reverse()
for (v, ind) in aa:
	ans += sum1[ind]
	for k in adl[ind]:
		adl[k].remove(ind)
		sum1[k] -= v
	adl[ind] = []
print(ans)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
graph = [[] for _ in range(n + 1)]
used = [False] * (n + 1)
energy = [0] + list(map(int, stdin.readline().split()))
sorted_energies = sorted(map(lambda x: (x[1], x[0]), enumerate(energy)), reverse=True)
result = 0
for _ in range(m):
	(a, b) = map(int, stdin.readline().split())
	graph[a].append(b)
	graph[b].append(a)
for item in sorted_energies:
	if not used[item[1]]:
		used[item[1]] = True
		for adj in graph[item[1]]:
			if not used[adj]:
				result += energy[adj]
stdout.write(str(result) + '\n')


from collections import defaultdict
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
graph = defaultdict(list)
visited = [0] * (n + 1)
for _ in range(m):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
data = dict.fromkeys(range(1, n + 1), 0)
for i in range(n + 1):
	data[i] = a[i - 1]
ans = 0
res = sorted(data, key=data.get, reverse=True)
for i in res:
	visited[i] = 1
	for j in graph[i]:
		if visited[j] == 0:
			ans += a[j - 1]
print(ans)


def solve():
	(numVertices, numEdges) = map(int, input().split())
	energyCost = [0] + list(map(int, input().split()))
	totalCost = sum((min(map(energyCost.__getitem__, map(int, input().split()))) for edge in range(numEdges)))
	print(totalCost)
solve()


ans = 0

def dfs(i):
	global ans
	x = i
	vis[i] = 1
	for j in grid[i]:
		ans += min(l[x - 1], l[j - 1])
		if vis[j] == 0:
			dfs(j)
for _ in range(1):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	grid = [[] for i in range(n + 1)]
	for i in range(k):
		(a, b) = map(int, input().split())
		grid[a].append(b)
		grid[b].append(a)
	vis = [0] * (n + 1)
	for i in range(1, n + 1):
		if vis[i] == 0:
			dfs(i)
	print(ans // 2)


(n, m) = map(int, input().split())
cost = [int(x) for x in input().split()]
arist = []
for i in range(m):
	(x, y) = map(int, input().split())
	arist.append((x, y))
graf = [[] for i in range(n)]
tup = [(cost[i], i) for i in range(len(cost))]
cos_amount = [0 for i in range(n)]
for i in arist:
	graf[i[0] - 1].append(i[1] - 1)
	graf[i[1] - 1].append(i[0] - 1)
	cos_amount[i[0] - 1] += cost[i[1] - 1]
	cos_amount[i[1] - 1] += cost[i[0] - 1]
sort = sorted(tup, key=lambda parameter_list: parameter_list[0], reverse=True)
sol = 0
for i in range(n - 1):
	part = sort[i]
	sol += cos_amount[part[1]]
	for j in range(len(graf[part[1]])):
		cos_amount[graf[part[1]][j]] -= part[0]
print(sol)


(n, m) = map(int, input().split())
arr = input('')
a = [0] + [int(i) for i in arr.split()]
ans = 0
for i in range(1, m + 1):
	(x, y) = map(int, input().split())
	ans = ans + min(a[x], a[y])
print(ans)


class IOHandlerObject(object):

	def getInput(self, mode=2):
		inputs = input().strip()
		if mode == 0:
			return inputs
		if mode == 1:
			return inputs.split()
		if mode == 2:
			return [int(x) for x in inputs.split()]

	def writeOutput(self, s='\n'):
		if isinstance(s, list):
			s = ' '.join(s)
		print(s)
IOHandler = IOHandlerObject()
g = IOHandler.getInput
w = IOHandler.writeOutput
(n, m) = g()
v = g()
sm = 0
for i in range(m):
	(x, y) = g()
	sm += min(v[x - 1], v[y - 1])
print(sm)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
from itertools import permutations
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
ans = 0
for _ in range(int(k)):
	(a, b) = map(int, input().split(' '))
	ans += min(l[a - 1], l[b - 1])
print(ans)


import logging
import copy
import sys
import math
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def solve(energy, lines):
	total = 0
	lMap = []
	for l in range(len(energy)):
		lMap.append([])
	for l in lines:
		(s, e) = (l[0] - 1, l[1] - 1)
		if energy[e] < energy[s]:
			(s, e) = (e, s)
		lMap[s].append(e)
	eList = []
	for (i, e) in enumerate(energy):
		eList.append([i, e])
	eList.sort(key=lambda x: x[1])
	total = 0
	for en in eList:
		(i, e) = (en[0], en[1])
		total += e * len(lMap[i])
	return total

def main():
	firstLine = input().split()
	firstLine = list(map(int, firstLine))
	energy = input().split()
	energy = list(map(int, energy))
	lines = []
	for i in range(firstLine[1]):
		line = input().split()
		line = list(map(int, line))
		lines.append(line)
	print(solve(energy, lines))

def log(*message):
	logging.debug(message)
main()


import sys
input_ = sys.stdin.readline
(parts, ropes) = tuple(map(int, input_().split()))
parts_cost = tuple(map(int, input_().split()))
minimum_cost = 0
for _ in range(ropes):
	(part1, part2) = tuple(map(int, input_().split()))
	cost1 = parts_cost[part1 - 1]
	cost2 = parts_cost[part2 - 1]
	minimum_cost += min(cost1, cost2)
print(minimum_cost)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
edges = []
for i in range(m):
	edge = list(map(int, input().split()))
	edges.append(edge)
ans = 0
for edge in edges:
	ans += min(a[edge[0] - 1], a[edge[1] - 1])
print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = [0] + arr
	order = sorted(range(n + 1), key=lambda x: arr[x])
	graph = [set() for _ in range(n + 1)]
	for _ in range(m):
		(a, b) = map(int, input().split())
		graph[a].add(b)
		graph[b].add(a)
	ans = 0
	for i in range(1, n + 1):
		z = arr[order[i]]
		zz = order[i]
		ans += len(graph[zz]) * z
		for item in graph[zz]:
			graph[item].remove(zz)
		graph[zz] = set()
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
v = list(map(int, input().split()))
s = 0
for _ in range(m):
	(x, y) = map(int, input().split())
	s += min(v[x - 1], v[y - 1])
print(s)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
suma = 0
for i in range(m):
	(s, e) = map(int, input().split())
	suma += min(l[s - 1], l[e - 1])
print(suma)


class graph(object):

	def __init__(self, n):
		self.nodes = [i + 1 for i in range(n)]
		self.edges = []

	def del_node(self, x):
		self.nodes.remove(x)

	def add_edge(self, x, y):
		self.edges.append(sorted([x, y]))

	def del_edge(self, x, y):
		if sorted([x, y]) in self.edges:
			self.edges.remove(sorted([x, y]))
(n, m) = input().split()
(n, m) = (int(n), int(m))
children = graph(n)
v = [int(i) for i in input().split()]
v = {i + 1: v[i] for i in range(len(v))}
for e in range(m):
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	children.add_edge(x, y)
energy = 0
while v != {}:
	min_energy = min(v.values())
	todelete = []
	for edge in children.edges:
		x = min(v[edge[0]], v[edge[1]])
		if x == min_energy:
			energy += min_energy
			todelete.append([edge[0], edge[1]])
	for deledge in todelete:
		children.del_edge(deledge[0], deledge[1])
	v = {x: v[x] for x in v if v[x] != min_energy}
print(energy)


(n, m) = map(int, input().split())
w = list(map(int, input().split()))
e = [[] for i in range(n)]
s = 0
for i in range(m):
	(u, v) = map(int, input().split())
	s += min(w[u - 1], w[v - 1])
print(s)


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
c = 0
for i in range(m):
	(x, y) = list(map(int, input().split()))
	c += min(l[x - 1], l[y - 1])
print(c)


R = lambda : map(int, input().split())
(m, n) = R()
tmp = R()
A = [0] + list(tmp)
summ = 0
for _ in range(n):
	(i, j) = R()
	summ += min(A[i], A[j])
print(summ)


from sys import stdin, stdout, setrecursionlimit
import threading

class Tail_Recursion_Optimization:

	def __init__(self, recursion_limit, stack_size):
		setrecursionlimit(recursion_limit)
		threading.stack_size(stack_size)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		(n, m) = [int(x) for x in R().split()]
		a = [0] + [int(x) for x in R().split()]
		min_energy = 0
		for i in range(m):
			(u, v) = [int(x) for x in R().split()]
			min_energy += min(a[u], a[v])
		W('%d\n' % min_energy)
		return 0

def main():
	s = SOLVE()
	s.solve()
threading.Thread(target=main).start()


(n, m) = map(int, input().split())
g = [[0] * n for i in range(n)]
v = list(map(int, input().split()))
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	g[x][y] = v[y]
	g[y][x] = v[x]
kek = sorted((i for i in range(n)), key=lambda x: v[x], reverse=True)
ans = 0
for i in kek:
	ans += sum(g[i])
	for j in range(n):
		if j != i:
			g[j][i] = 0
print(ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, m) = invr()
ans = 0
arr = inlt()
for i in range(m):
	(a, b) = invr()
	ans += min(arr[b - 1], arr[a - 1])
print(ans)


def Solve():
	(n, m) = map(int, input().split())
	cost = [int(x) for x in input().split()]
	c = 0
	for _ in range(m):
		(x, y) = map(int, input().split())
		c += min(cost[x - 1], cost[y - 1])
	print(c)
Solve()


(n, m) = [int(i) for i in input().split()]
energy = [int(i) for i in input().split()]
result = 0
for i in range(m):
	(x, y) = [int(i) for i in input().split()]
	result += min(energy[x - 1], energy[y - 1])
print(result)


from itertools import combinations

def input_ints():
	return list(map(int, input().split()))

def output_list(v):
	print(' '.join((str(x) for x in v)))

def main():
	(n, m) = input_ints()
	v = input_ints()
	ans = 0
	for i in range(m):
		(x, y) = input_ints()
		ans += min(v[x - 1], v[y - 1])
	print(ans)
main()


(n, m) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
total = 0
for i in range(m):
	(a, b) = [int(i) for i in input().split()]
	total += min(arr[a - 1], arr[b - 1])
print(total)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
adj = list((tuple(map(int, input().split())) for _ in range(m)))
res = 0
for (i, j) in adj:
	res += min(arr[i - 1], arr[j - 1])
print(res)


from collections import deque
(n, m) = map(int, input().split())
original_nodes = input().split()
nodes = [(int(index), int(value)) for (index, value) in enumerate(original_nodes, start=0)]
edges = []
[edges.append([]) for x in range(n)]
for something in range(m):
	(v1, v2) = map(int, input().split())
	edges[v1 - 1].append(v2 - 1)
	edges[v2 - 1].append(v1 - 1)
nodes.sort(key=lambda x: x[1], reverse=True)
energy = 0
nodes = deque(nodes)
for x in range(n):
	node = nodes.popleft()
	for adj_node in edges[node[0]]:
		energy += int(original_nodes[adj_node])
		edges[adj_node].remove(node[0])
	edges[node[0]] = []
print(energy)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
u = 0
for i in range(m):
	(a, b) = map(int, input().split())
	u += min(l[a - 1], l[b - 1])
print(u)


def solve():
	(numVertices, numEdges) = map(int, input().split())
	energyCost = tuple(map(int, input().split()))
	print(sum((min((energyCost[v - 1] for v in map(int, input().split()))) for edge in range(numEdges))))
solve()


(n, m) = map(int, input().split())
v = [0] + list(map(int, input().split()))
r = 0
for i in range(m):
	r += min((v[i] for i in map(int, input().split())))
print(r)


(n, m) = map(int, input().split())
r = sorted(enumerate(map(int, input().split())), key=lambda x: x[1])
p = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(lambda n: int(n) - 1, input().split())
	p[x] += [y]
	p[y] += [x]
q = [len(i) for i in p]
s = 0
for (x, f) in r:
	s += q[x] * f
	for y in p[x]:
		q[y] -= 1
print(s)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
d = []
d2 = []
for i in range(m):
	(x, y) = map(int, input().split())
	d.append(min(arr[x - 1], arr[y - 1]))
print(sum(d))


(n, m) = map(int, input().split())
vals = list(map(int, input().split()))
adj = [list() for i in range(n)]
lst = [i for i in range(n)]
sums = [0 for i in range(n)]
for i in range(m):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	adj[u].append(v)
	adj[v].append(u)
	sums[u] += vals[v]
	sums[v] += vals[u]
res = 0
lst.sort(key=lambda x: vals[x], reverse=True)
for i in range(n):
	v = lst[0]
	lst = lst[1:]
	res += sums[v]
	for ele in adj[v]:
		sums[ele] -= vals[v]
print(res)


def main():
	(n, m) = map(int, input().split())
	(v, ans) = (list(map(int, input().split())), 0)
	for i in range(m):
		ans += min((v[int(x) - 1] for x in input().split()))
	print(ans)
main()


(n, m) = map(int, input().split())
v = list(map(int, input().split()))
r = [set() for i in range(n)]
for i in range(m):
	(n1, n2) = (int(x) - 1 for x in input().split())
	r[n1].add(n2)
	r[n2].add(n1)
val = 0
for x in reversed(sorted(((x, i) for (i, x) in enumerate(v)))):
	for y in r[x[1]]:
		val += v[y]
		r[y].remove(x[1])
print(val)


(n, m) = [int(x) for x in input().split()]
energy = list(map(int, input().split()))
rope = []
for i in range(m):
	l = list(map(int, input().split()))
	rope.append(l)
dic = {}
for i in range(n):
	dic[i + 1] = 0
for i in range(n):
	dic[i + 1] = energy[i]
for i in range(m):
	a = dic[rope[i][0]]
	b = dic[rope[i][1]]
	rope[i] = min(a, b)
print(sum(rope))


maxx = int(1000000000.0)

def getVals(type=str):
	return list(map(type, input().split()))

class Node:

	def __init__(self, val):
		self.val = val
		self.left = None
		self.right = None
		self.height = 1

class AVL:

	def getHeight(self, node):
		if node == None:
			return 0
		return node.height

	def getBalance(self, node):
		if node == None:
			return 0
		return self.getHeight(node.left) - self.getHeight(node.right)

	def leftRotate(self, node):
		x = node.right
		y = x.left
		x.left = node
		node.right = y
		node.height = 1 + max(self.getHeight(node.left), self.getHeight(node.right))
		x.height = 1 + max(self.getHeight(x.left), self.getHeight(x.right))
		return x

	def rightRotate(self, node):
		x = node.left
		y = x.right
		x.right = node
		node.left = y
		node.height = 1 + max(self.getHeight(node.left), self.getHeight(node.right))
		x.height = 1 + max(self.getHeight(x.left), self.getHeight(x.right))
		return x

	def rebalance(self, node, val):
		balance = self.getBalance(node)
		if balance > 1:
			if val > node.left.val:
				node.left = self.leftRotate(node.left)
			return self.rightRotate(node)
		if balance < -1:
			if val < node.right.val:
				node.right = self.rightRotate(node.right)
			return self.leftRotate(node)
		return node

	def getMinValNode(self, node):
		if node is None or node.left is None:
			return node
		return self.getMinValNode(node.left)

	def insertNode(self, node, val):
		if node == None:
			return Node(val)
		if node.val > val:
			node.left = self.insertNode(node.left, val)
		else:
			node.right = self.insertNode(node.right, val)
		node.height = 1 + max(self.getHeight(node.left), self.getHeight(node.right))
		return self.rebalance(node, val)

	def deleteNode(self, node, val):
		if node == None:
			return node
		if node.val > val:
			node.left = self.deleteNode(node.left, val)
		elif node.val < val:
			node.right = self.deleteNode(node.right, val)
		else:
			if node.left == None:
				tempNode = node.right
				node = None
				return tempNode
			elif node.right == None:
				tempNode = node.left
				node = None
				return tempNode
			tempNode = self.getMinValNode(node.right)
			node.val = tempNode.val
			node.right = self.deleteNode(node.right, tempNode.val)
		node.height = 1 + max(self.getHeight(node.left), self.getHeight(node.right))
		return self.rebalance(node, val)

	def preOrder(self, node):
		ans = []
		if node != None:
			ans += self.preOrder(node.left)
			ans += [node.val]
			ans += self.preOrder(node.right)
		return ans
ST = [[maxx, maxx, maxx] for i in range(int(100000.0))]

def buildST():
	for i in range(n - 1, 0, -1):
		ST[i] = min(ST[i << 1], ST[i << 1 | 1])

def updateST(idx, val):
	idx += n
	ST[idx][1] = val
	while idx > 1:
		ST[idx >> 1] = min(ST[idx], ST[idx ^ 1])
		idx >>= 1

def queryMinST(l, r):
	l += n
	r += n
	query = [maxx, maxx, maxx]
	while l < r:
		if l & 1:
			query = min(query, ST[l])
			l += 1
		if r & 1:
			r -= 1
			query = min(query, ST[r])
		l >>= 1
		r >>= 1
	return query
(n, m) = getVals(int)
costs = getVals(int)
adjList = [None for i in range(n)]

def solve(n, m):
	for i in range(n):
		ST[i + n][0] = -costs[i]
		ST[i + n][1] = 0
		ST[i + n][2] = i
	for i in range(m):
		(x, y) = getVals(int)
		x -= 1
		y -= 1
		adjList[x] = AVL().insertNode(adjList[x], y)
		adjList[y] = AVL().insertNode(adjList[y], x)
		ST[x + n][1] += costs[y]
		ST[y + n][1] += costs[x]
	buildST()
	ans = 0
	for i in range(n):
		(temp, val, idx) = queryMinST(0, n)
		ans += val
		L = AVL().preOrder(adjList[idx])
		ST[idx + n][0] = 0
		updateST(idx, int(1000000000.0))
		for num in L:
			updateST(num, ST[num + n][1] - costs[idx])
		adjList[idx] = None
	return ans
print(solve(n, m))


(n, m) = map(int, input().split())
v = list(map(int, input().split()))
graph = [set() for _ in range(n)]
strengths = list()
ans = 0
for i in range(m):
	(x, y) = map(int, input().split())
	graph[x - 1].add(y - 1)
	graph[y - 1].add(x - 1)
for i in range(n):
	strengths.append([v[i], i])
strengths = list(reversed(sorted(strengths)))
while len(strengths) > 0:
	(vi, i) = strengths.pop(0)
	ans += sum((v[j] for j in graph[i]))
	for s in strengths:
		if i in graph[s[1]]:
			graph[s[1]].remove(i)
print(ans)


from collections import *
from sys import stdin

def arr_enu():
	return [[i + 1, int(x)] for (i, x) in enumerate(stdin.readline().split())]

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return [str(x) for x in stdin.readline().split()]

def calulate_cost():
	cost = {}
	for i in range(1, n + 1):
		tem = 0
		for j in toy.gdict[i]:
			tem += energy[j - 1][1]
		cost[i] = tem
	return cost

def change(v):
	for i in toy.gdict[v]:
		try:
			cost[i] -= dic[v]
		except:
			continue

class graph:

	def __init__(self, gdict=None):
		if gdict is None:
			gdict = defaultdict(list)
		(self.gdict, self.edges) = (gdict, [])

	def get_vertices(self):
		return list(self.gdict.keys())

	def add_edge(self, node1, node2):
		self.gdict[node1].append(node2)
		self.gdict[node2].append(node1)
		self.edges.append([node1, node2])
(n, m) = arr_inp(1)
(toy, energy) = (graph(), arr_enu())
for i in range(m):
	(u, v) = arr_inp(1)
	toy.add_edge(u, v)
(cost, ans, dic) = (calulate_cost(), 0, {i: j for (i, j) in energy})
energy.sort(key=lambda x: x[1])
for i in range(n):
	ma = energy[-1][0]
	ans += cost[ma]
	change(ma)
	del cost[ma]
	energy.pop()
print(ans)


import sys
(n, m) = map(int, sys.stdin.readline().split())
l = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(m):
	(x, y) = map(int, sys.stdin.readline().split())
	ans += min(l[x - 1], l[y - 1])
print(ans)


__author__ = 'asmn'
import sys
(n, m) = tuple(map(int, input().split()))
v = list(map(int, input().split()))
e = [[] for i in range(n)]
for k in range(m):
	(x, y) = tuple(map(int, input().split()))
	e[x - 1].append(y - 1)
	e[y - 1].append(x - 1)
nx = sorted(list(range(n)), key=lambda x: v[x], reverse=True)
used = set()
ans = 0
for x in nx:
	for y in e[x]:
		if y not in used:
			ans += v[y]
	used.add(x)
print(ans)


(N, M) = list(map(int, input().split(' ')))
cost = list(map(int, input().split(' ')))
cost.insert(0, -1)
adjacency_list = [[] for i in range(N + 1)]
for i in range(M):
	(a, b) = list(map(int, input().split(' ')))
	adjacency_list[a].append(b)
	adjacency_list[b].append(a)
nodes_by_cost = list(reversed(sorted([x + 1 for x in range(N)], key=lambda y: cost[y])))
total_cost = 0
deleted = [False for x in range(N + 1)]
for node in nodes_by_cost:
	cost_for_removing_node = 0
	for neig in adjacency_list[node]:
		if not deleted[neig]:
			cost_for_removing_node += cost[neig]
	deleted[node] = True
	total_cost += cost_for_removing_node
print(total_cost)


import sys
(n, m) = map(int, input().split())
v = [int(x) for x in input().split()]
v.insert(0, 0)
ans = 0
for _ in range(m):
	(x, y) = map(int, input().split())
	ans += min(v[x], v[y])
print(ans)


(n, m) = map(int, input().split())
e = list(map(int, input().split()))
res = 0
for _ in range(m):
	(u, v) = map(int, input().split())
	res += min(e[u - 1], e[v - 1])
print(res)


from collections import defaultdict
(n, m) = map(int, input().split())
graph = defaultdict(list)
l = list(map(int, input().split()))
for i in range(1, n + 1):
	graph[i] = []
for i in range(m):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
val = []
for i in range(1, n + 1):
	val.append([i, l[i - 1]])
val = sorted(val, key=lambda x: x[1])
total = 0
for (node1, value) in val:
	for node2 in graph[node1]:
		total += value
		graph[node2].remove(node1)
print(total)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
(n, m) = mi()
cnct = [set() for _ in range(n + 1)]
cost = [0] * (n + 1)
val = dict()
a = li()
c = 1
for i in a:
	if i not in val:
		val[i] = {c}
	else:
		val[i].update({c})
	c += 1
for _ in range(m):
	(x, y) = mi()
	cnct[x].add(y)
	cnct[y].add(x)
	cost[x] += a[y - 1]
	cost[y] += a[x - 1]
a.sort(reverse=True)
cnt = 0
for i in a:
	x = val[i].pop()
	cnt += cost[x]
	for el in cnct[x]:
		cost[el] -= i
		cnct[el].remove(x)
print(cnt)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
adj = [[] for i in range(n + 1)]
for j in range(m):
	(a, b) = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
ans = 0
u = []
for j in range(n + 1):
	for k in adj[j]:
		if k > j:
			ans += min(t[k - 1], t[j - 1])
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	(u, v) = map(int, input().split())
	ans += min(a[u - 1], a[v - 1])
print(ans)


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
s = 0
for i in range(m):
	(x, y) = map(int, input().split())
	s += min(lst[x - 1], lst[y - 1])
print(s)


read = lambda : map(int, input().split())
(n, m) = read()
cost = list(read())
ans = 0
for i in range(m):
	(v, u) = read()
	ans += min(cost[v - 1], cost[u - 1])
print(ans)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
res = 0
for _ in range(m):
	(x, y) = map(int, input().split())
	res += min(arr[x - 1], arr[y - 1])
print(res)


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		(n, m) = invr()
		a = inlt()
		values = dict(sorted({i: k for (i, k) in zip(range(1, n + 1), a)}.items(), key=lambda x: x[1], reverse=True))
		edges = [[0 for __ in range(n + 1)] for _ in range(n + 1)]
		ans = 0
		for _ in range(m):
			(a, b) = invr()
			edges[a][b] = 1
			edges[b][a] = 1
		for (x, y) in values.items():
			for i in range(n):
				if edges[x][i + 1]:
					ans += values[i + 1]
				edges[x][i + 1] = 0
				edges[i + 1][x] = 0
		print(ans)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


__author__ = 'artyom'

def read_int_ary():
	return map(int, input().split())
(n, m) = read_int_ary()
v = [None] + list(read_int_ary())
cost = 0
for _ in range(m):
	(a, b) = read_int_ary()
	cost += min(v[a], v[b])
print(cost)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
(n, k) = value()
a = array()
ans = 0
for _ in range(k):
	(s, e) = value()
	ans += min(a[s - 1], a[e - 1])
print(ans)


(n, m) = map(int, input().split())
(a, s) = (list(map(int, input().split())), 0)
for i in range(m):
	(q, w) = map(int, input().split())
	s += min(a[q - 1], a[w - 1])
print(s)


R = lambda : map(int, input().split())
(n, m) = R()
v = [0] + list(R())
print(sum((min(v[x], v[y]) for (x, y) in (R() for i in range(m)))))


(n, m) = [int(c) for c in input().split()]
v = [0] + [int(c) for c in input().split()]
chains = [[] for _ in range(n + 1)]
for i in range(m):
	(a, b) = [int(c) for c in input().split()]
	chains[a].append(b)
	chains[b].append(a)
res = 0
for i in range(n):
	m = 0
	ind = 0
	for j in range(len(v)):
		if v[j] > m:
			m = v[j]
			ind = j
	res += sum([v[_] for _ in chains[ind]])
	v[ind] = 0
print(res)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
num = 0
for i in range(m):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	num += min(x[a], x[b])
print(num)


(n, m) = list(map(int, input().split()))
cs = [0] + list(map(int, input().split()))
mls = [0 for i in range(n + 1)]
for i in range(m):
	(x, y) = list(map(int, input().split()))
	if cs[y] < cs[x]:
		(x, y) = (y, x)
	mls[x] += 1
print(sum([cs[i] * mls[i] for i in range(n + 1)]))


(n, m) = [int(x) for x in input().strip().split()]
energy = [int(x) for x in input().strip().split()]
d = {i: [] for i in range(1, n + 1)}
for i in range(m):
	(k, l) = [int(x) for x in input().strip().split()]
	d[k].append(l)
	d[l].append(k)
s_energy = sorted(list(zip(list(range(1, n + 1)), energy)), key=lambda x: -x[1])
cost = 0
visited = [False] * n
for (part, val) in s_energy:
	visited[part - 1] = True
	for i in d[part]:
		if not visited[i - 1]:
			cost += energy[i - 1]
print(cost)


class pair:

	def __init__(self, first, second):
		self.first = first
		self.second = second

def ans(graph, v, n):
	result = 0
	arr = []
	for i in range(0, n):
		arr.append(pair(v[i], i))
	arr.sort(key=lambda p: (p.first, p.second))
	arr.reverse()
	for i in range(0, n):
		for j in graph[arr[i].second]:
			result += v[j]
		v[arr[i].second] = 0
	return result
(n, m) = map(int, input().split())
v = list(map(int, input().split()))
graph = [[] for i in range(0, 1001)]
for _ in range(0, m):
	(x, y) = map(int, input().split())
	graph[x - 1].append(y - 1)
	graph[y - 1].append(x - 1)
print(ans(graph, v, n))


def main():
	(n, m) = map(int, input().split())
	(v, g) = (list(map(int, input().split())), [0] * n)
	(graph, visited) = ([[] for i in range(n)], [0] * n)
	stack = []
	for i in range(m):
		(s, t) = map(lambda x: int(x) - 1, input().split())
		graph[s].append(t)
		graph[t].append(s)
		g[s] += 1
		g[t] += 1

	def process(u):
		if not g[u]:
			return 0
		ans = g[u] * v[u]
		for t in graph[u]:
			g[t] -= 1
			g[u] -= 1
		return ans

	def dfs(u):
		visited[u] = 1
		for v in graph[u]:
			if not visited[v]:
				dfs(v)
		stack.append(u)
	ans = 0
	for i in range(n):
		if not visited[i]:
			dfs(i)
			ans += sum(map(process, sorted(stack, key=lambda x: v[x])))
			stack.clear()
	print(ans)
main()


(n, m) = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
sum = 0
for i in range(m):
	(x, y) = [int(i) for i in input().split()]
	sum += min(v[x - 1], v[y - 1])
print(sum)


maxx = int(1000000000.0)

def getVals(type=str):
	return list(map(type, input().split()))
(n, m) = getVals(int)
costs = getVals(int)
total = [0 for i in range(n)]
adj = [[] for i in range(n)]

def solve(n, m):
	ans = 0
	for i in range(m):
		(x, y) = getVals(int)
		x -= 1
		y -= 1
		total[x] += costs[y]
		adj[x].append(y)
		total[y] += costs[x]
		adj[y].append(x)
	L = []
	for i in range(n):
		L.append([costs[i], i])
	L.sort()
	for i in range(n - 1, -1, -1):
		ans += total[L[i][1]]
		for num in adj[L[i][1]]:
			total[num] -= costs[L[i][1]]
	return ans
print(solve(n, m))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, m) = I()
l = I()
ans = 0
for i in range(m):
	(x, y) = I()
	ans += min(l[x - 1], l[y - 1])
print(ans)


energy = 0
(n, m) = [int(x) for x in input().split()]
prices = [None] + [int(x) for x in input().split()]
for _ in range(m):
	(a, b) = [int(x) for x in input().split()]
	energy += min(prices[a], prices[b])
print(energy)


a = list(map(int, input().strip(' ').split(' ')))
s = list(map(int, input().strip(' ').split(' ')))
s.insert(0, 0)
sum1 = 0
for i in range(a[1]):
	d = list(map(int, input().strip(' ').split(' ')))
	sum1 += min(s[d[0]], s[d[1]])
print(sum1)


import sys

def answer(n, m, v, x, y):
	total = 0
	for i in range(m):
		total += min(v[x[i]], v[y[i]])
	return total

def main():
	(n, m) = map(int, sys.stdin.readline().split())
	v = [0]
	v.extend(list(map(int, sys.stdin.readline().split())))
	x = [0 for _ in range(m)]
	y = [0 for _ in range(m)]
	for i in range(m):
		(x[i], y[i]) = map(int, sys.stdin.readline().split())
	print(answer(n, m, v, x, y))
	return
main()


def R():
	return map(int, input().split())
(n, m) = R()
arr = list(R())
print(sum((min((arr[j - 1] for j in R())) for i in range(m))))


(n, m) = map(int, input().split())
a = [0] + list(map(int, input().split()))
c = [0] * (n + 1)
edge = [[] for i in range(n + 1)]
for i in range(m):
	(u, v) = map(int, input().split())
	edge[u].append(v)
	edge[v].append(u)
	c[u] += a[v]
	c[v] += a[u]
ans = 0
order = sorted(list(range(1, n + 1)), key=lambda x: -a[x])
for idx in order:
	ans += c[idx]
	for to in edge[idx]:
		c[to] -= a[idx]
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
sum = 0
for _ in range(m):
	(u, v) = map(int, input().split())
	sum += min(arr[u - 1], arr[v - 1])
print(sum)


(n, m) = map(int, input().split())
r = list(enumerate(map(int, input().split()), 1))
r.sort(key=lambda x: x[1])
(s, p) = (0, [[] for i in range(n + 1)])
for i in range(m):
	(x, y) = map(int, input().split())
	p[x].append(y)
	p[y].append(x)
q = [len(t) for t in p]
for (x, f) in r:
	s += f * q[x]
	for y in p[x]:
		q[y] -= 1
print(s)


class Graph:

	def __init__(self, v, node_val):
		self.v = v
		self.graph = [[0 for i in range(v)] for i in range(v)]
		self.node_val = node_val

	def addEdge(self, u, v):
		self.graph[u][v] = 1
		self.graph[v][u] = 1

	def delEdge(self, u, v):
		self.graph[u][v] = 0
		self.graph[v][u] = 0
(n, m) = [int(x) for x in input().split()]
val = [int(x) for x in input().split()]
edges = []
for _ in range(m):
	edges.append([int(x) for x in input().split()])
node_val = {i: val[i] for i in range(len(val))}
node_val = dict(sorted(node_val.items(), key=lambda x: x[1], reverse=True))
V = len(node_val)
g = Graph(len(node_val), node_val)
for [u, v] in edges:
	g.addEdge(u - 1, v - 1)
ans = 0
for k in node_val.keys():
	for i in range(V):
		if g.graph[k][i] == 1:
			g.delEdge(k, i)
			ans += node_val[i]
print(ans)


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.buffer.readline())
Neo = lambda : list(map(int, sys.stdin.buffer.readline().split()))
(n, m) = Neo()
A = Neo()
Ans = 0
for i in range(m):
	(x, y) = Neo()
	Ans += min(A[x - 1], A[y - 1])
print(Ans)


(n, m) = map(int, input().split())
from collections import defaultdict
v = [0] * (n + 1)
adj = []
for i in range(n + 1):
	adj.append([])
l = list(map(int, input().split()))
d = defaultdict(list)
for i in range(m):
	(x, y) = map(int, input().split())
	adj[x].append(y)
	adj[y].append(x)
	d[x] = [0] * (n + 1)
	d[y] = [0] * (n + 1)
ans = 0

def dfs(x):
	global ans
	v[x] = 1
	for i in adj[x]:
		if not v[i]:
			ans += min(l[i - 1], l[x - 1])
			d[x][i] = 1
			d[i][x] = 1
			dfs(i)
		elif d[x][i] == 0 or d[i][x] == 0:
			ans += min(l[i - 1], l[x - 1])
			d[x][i] = 1
			d[i][x] = 1
for i in range(1, n + 1):
	if not v[i]:
		dfs(i)
print(ans)


I = lambda : list(map(int, input().split()))
(n, m) = I()
l = I()
ans = 0
for i in range(m):
	(x, y) = I()
	ans += min(l[x - 1], l[y - 1])
print(ans)


from collections import defaultdict

def read():
	return map(int, input().strip().split())
(n, m) = read()
e = list(read())
e = [(x, i) for (i, x) in enumerate(e)]
g = defaultdict(list)
for _ in range(m):
	(u, v) = read()
	u -= 1
	v -= 1
	g[u].append(v)
	g[v].append(u)
cost = 0
for x in reversed(sorted(e)):
	u = x[1]
	e_ = x[0]
	for v in g[u]:
		cost += min(e[u][0], e[v][0])
		g[v].remove(u)
print(cost)


(n, m) = map(int, input().split(' '))
v = list(map(int, input().split(' ')))
vd = {}
for (i, x) in enumerate(v):
	vd[i] = x
g = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split(' '))
	x -= 1
	y -= 1
	g[x].append(y)
	g[y].append(x)
v = [[-x, i] for (i, x) in enumerate(v)]
v.sort()
ans = 0
removed = [0] * n
for i in range(n):
	x = v[i][1]
	removed[x] = 1
	for y in g[x]:
		if not removed[y]:
			ans += vd[y]
print(ans)


(n, m) = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0
for _ in range(m):
	(a, b) = list(map(int, input().split()))
	ans += min(v[a - 1], v[b - 1])
print(ans)


(n, m) = map(int, input().split())
values = [-10000] + list(map(int, input().split()))
g = [[] for i in range(n + 10)]
costs = [0] * (n + 10)
for i in range(m):
	(u, v) = map(int, input().split())
	g[u] += [v]
	g[v] += [u]
for i in range(1, n + 1):
	for neighbor in g[i]:
		costs[i] += values[neighbor]
for i in range(0, n + 1):
	values[i] = (values[i], i)
values = sorted(values, reverse=True)
total = 0
for i in range(0, n):
	node = values[i][1]
	cost = values[i][0]
	total += costs[node]
	for neighbor in g[node]:
		costs[neighbor] -= cost
print(total)


from sys import stdin
M = lambda : map(int, stdin.readline().split())
(n, m) = M()
p = list(M())
ans = 0
for i in range(m):
	(x, y) = M()
	ans += min(p[x - 1], p[y - 1])
print(ans)


(n, m) = [int(i) for i in input().split()]
x = input().split()
popa = [[int(x[i]), i] for i in range(n)]
graph = [[] for i in range(n + 1)]
for i in range(m):
	(x, y) = map(int, input().split())
	graph[x].append(y)
	graph[y].append(x)
popa = sorted(popa)[::-1]
dic = {i[1] + 1: i[0] for i in popa}
suma = 0
d = []
for x in popa:
	v = x[1] + 1
	for i in graph[v]:
		if i not in d:
			suma += dic[i]
	d.append(v)
print(suma)


(n, m) = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
a = [[] for x in range(n)]
used = [0] * n
for i in range(m):
	(x, y) = [int(x) for x in input().split()]
	x -= 1
	y -= 1
	a[x].append(y)
	a[y].append(x)
l = sorted(zip(v, range(n)), key=lambda x: -x[0])
ans = 0
for (_, i) in l:
	used[i] = 1
	for x in a[i]:
		if not used[x]:
			ans += v[x]
print(ans)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().strip()
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
(n, m) = ilele()
A = alele()
ans = 0
for i in range(m):
	(a, b) = ilele()
	ans += min(A[a - 1], A[b - 1])
print(ans)


from collections import defaultdict
graph = defaultdict(set)
(n, m) = map(int, input().split())
cost = list(map(int, input().split()))
remove_cost = [0 for _ in range(n)]
for _ in range(m):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	graph[u].add(v)
	graph[v].add(u)
	remove_cost[u] += cost[v]
	remove_cost[v] += cost[u]
order = sorted([(i, x) for (i, x) in enumerate(cost)], key=lambda x: x[1], reverse=True)
components = n
total = 0
removed = set()
for (i, x) in order:
	r_cost = remove_cost[i]
	total += r_cost
	for connected in graph[i]:
		remove_cost[connected] -= cost[i]
print(total)


(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
print(sum((min(a[x - 1], a[y - 1]) for (x, y) in (map(int, input().split(' ')) for i in range(m)))))


from operator import itemgetter
(n, m) = map(int, input().split())
vi = list(map(int, input().split()))
ai = [[vi[i], i] for i in range(n)]
ai3 = [0] * n
ar = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	ai3[x] += vi[y]
	ai3[y] += vi[x]
	ar[x] += [y]
	ar[y] += [x]
ai.sort(key=itemgetter(0))
ans = 0
for i in range(n - 1, 0, -1):
	ans += ai3[ai[i][1]]
	for j in ar[ai[i][1]]:
		ai3[j] -= vi[ai[i][1]]
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
su = 0
for i in range(k):
	(a, b) = map(int, input().split())
	su += min(l[a - 1], l[b - 1])
print(su)


I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input().split()))
from collections import OrderedDict
(n, m) = I()
l = I()
t = {}
t1 = {}
for i in range(n):
	t1[i + 1] = l[i]
t1 = sorted(t1.items(), key=lambda kv: kv[1], reverse=True)
t1 = [(0, 0)] + t1
z = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(1, m + 1):
	(a, b) = I()
	z[a][b] = 1
	z[b][a] = 1
s = 0
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if z[t1[i][0]][j] == 1:
			s += l[j - 1]
			z[j][t1[i][0]] = 0
print(s)


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
sm = 0
for i in range(m):
	(l, r) = map(int, input().split())
	sm += min(lis[l - 1], lis[r - 1])
print(sm)


l = lambda : map(int, input().split())
(n, m) = l()
v = [0] + list(l())
print(sum((min(v[x], v[y]) for (x, y) in (l() for _ in ' ' * m))))


(n, m) = map(int, input().split())
w = list(map(int, input().split()))
ans = 0
for i in range(m):
	(x, y) = map(int, input().split())
	ans += min(w[x - 1], w[y - 1])
print(ans)


def mapit():
	temp = list(map(int, input().split()))
	return temp

def solution():
	(n, m) = mapit()
	val = mapit()
	connect = [0] * n
	removed = set()
	for i in range(m):
		(x, y) = mapit()
		if connect[x - 1] == 0:
			connect[x - 1] = [(y - 1, val[y - 1])]
		else:
			connect[x - 1].append((y - 1, val[y - 1]))
		if connect[y - 1] == 0:
			connect[y - 1] = [(x - 1, val[x - 1])]
		else:
			connect[y - 1].append((x - 1, val[x - 1]))
	prio = []
	for i in range(n):
		prio.append((val[i], i))
	prio.sort()
	ans = 0
	while prio:
		curr = prio.pop()
		curr_node = curr[1]
		removed.add(curr_node)
		if connect[curr_node] != 0:
			for (node, value) in connect[curr_node]:
				if node not in removed:
					ans += value
	print(ans)
	return
solution()


(x, y) = input().split()
a = list(map(int, input().split()))
ans = 0
for i in range(0, int(y)):
	(v1, v2) = input().split()
	ans += min(a[int(v1) - 1], a[int(v2) - 1])
print(ans)


t = input().split()
n = int(t[0])
m = int(t[1])
slon = 0
num = [int(x) for x in input().split()]
for i in range(m):
	t = input().split()
	slon += min(num[int(t[0]) - 1], num[int(t[1]) - 1])
print(slon)


(n, m) = list(map(int, input().split()))
v = list(map(int, input().split()))
soma = 0
for i in range(m):
	(x, y) = list(map(int, input().split()))
	soma += min(v[x - 1], v[y - 1])
print(soma)


l2 = input().split()
n = int(l2[0])
m = int(l2[1])
l = [int(y) for y in input().split()]
sum = 0
for i in range(m):
	l1 = [int(x) for x in input().split()]
	sum = sum + min(l[l1[0] - 1], l[l1[1] - 1])
print(sum)


R = lambda : map(int, input().split())
(n, m) = R()
v = list(R())
g = [set() for i in range(n + 1)]
for i in range(m):
	(x, y) = R()
	g[x].add(y)
	g[y].add(x)
s = 0
for (w, i) in sorted(zip(v, range(1, n + 1)), reverse=True):
	for j in g[i]:
		s += v[j - 1]
		g[j].remove(i)
print(s)


(n, m) = map(int, input().split(' '))
ar = list(map(int, input().split(' ')))
mx = 0
for i in range(m):
	(x, y) = map(int, input().split(' '))
	mx = mx + min(ar[x - 1], ar[y - 1])
print(mx)


(n, m) = map(int, input().split())
cost = [0] + list(map(int, input().split()))
res = 0
for i in range(m):
	(x, y) = map(int, input().split())
	res += min(cost[x], cost[y])
print(res)


(n, m) = map(int, input().split())
arr = [0] + list(map(int, input().split()))
ans = 0
for _ in range(m):
	(u, v) = map(int, input().split())
	ans += min(arr[u], arr[v])
print(ans)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
v = list(map(int, stdin.readline().split()))
g = [list() for i in range(n)]
for i in range(m):
	(x, y) = map(int, stdin.readline().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)

def main():
	res = 0
	vis = [False for i in range(n)]
	q = []
	q.append(0)
	vis[0] = True
	mp = dict()
	for (i, _) in enumerate(g):
		for j in g[i]:
			if mp.get((i, j), 0) == 0 and mp.get((j, i), 0) == 0:
				res += min(v[i], v[j])
				mp[i, j] = 1
				mp[j, i] = 1
	stdout.write(str(res))
main()


def main():
	from heapq import heapify, heappop
	(n, m) = [int(i) for i in input().split()]
	energy = [[int(v), i] for (i, v) in enumerate(input().split())]
	s_energy = sorted(energy)
	graph = [set() for i in range(n)]
	for i in range(m):
		(x, y) = [int(i) for i in input().split()]
		graph[x - 1].add(y - 1)
		graph[y - 1].add(x - 1)
	result = 0
	for i in range(n):
		(e, x) = s_energy.pop()
		for j in graph[x]:
			graph[j].remove(x)
			result += energy[j][0]
	print(result)
main()


def main():
	(n, m) = map(int, input().split())
	vv = list(map(int, input().split()))
	print(sum((min((vv[i - 1] for i in map(int, input().split()))) for _ in range(m))))

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
arr.insert(0, 0)
graph = [[] for i in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
energy = []
a = 1
for i in arr[1:]:
	energy.append([i, a])
	a += 1
energy.sort(reverse=True)
ans = 0
for i in energy:
	tgraph = graph[i[1]][:]
	for j in tgraph:
		ans += min(i[0], arr[j])
		graph[i[1]].remove(j)
		graph[j].remove(i[1])
print(ans)


from sys import stdin, stdout
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
import heapq
(n, m) = mp()
l = sorted(list(enumerate(mp(), 1)), key=lambda x: x[1])
d = dd(list)
visited = set()
for _ in range(m):
	(a, b) = mp()
	d[a].append(b)
	d[b].append(a)
ans = 0
for i in range(n):
	for j in d[l[i][0]]:
		if (j, l[i][0]) in visited or (l[i][0], j) in visited:
			pass
		else:
			ans += l[i][1]
			visited.add((j, l[i][0]))
			visited.add((l[i][0], j))
print(ans)


(n, m) = map(int, input().split())
v = [int(elm) for elm in input().split()]
ans = 0
for i in range(m):
	(x, y) = map(int, input().split())
	ans += min(v[x - 1], v[y - 1])
print(ans)


from sys import stdin
input = stdin.readline
IN = lambda : map(int, input().split())
(n, m) = IN()
a = [0, *IN()]
sum = 0
for i in range(m):
	(x, y) = IN()
	sum += min(a[x], a[y])
print(sum)


dic = {}
(n, m) = map(int, input().split())
v = [int(x) for x in input().split()]
for i in range(m):
	(x, y) = [int(x) - 1 for x in input().split()]
	if x not in dic:
		dic[x] = [y]
	else:
		dic[x].append(y)
	if y not in dic:
		dic[y] = [x]
	else:
		dic[y].append(x)
lst = [[v[x], x] for x in range(n)]
lst.sort(reverse=True)
cost = 0
for i in lst:
	if i[1] in dic:
		for j in dic[i[1]]:
			cost += v[j]
	v[i[1]] = 0
print(cost)


(n, m) = map(int, input().split())
v = [0] + [int(i) for i in input().split()]
energy = 0
for i in range(m):
	(a, b) = map(int, input().split())
	energy += min(v[a], v[b])
print(energy)


def find_min(arr, n):
	mi = 0
	ind = -1
	for i in range(n):
		if arr[i] > mi:
			mi = arr[i]
			ind = i
	return ind + 1

class node:

	def __init__(self):
		self.list = []

	def ad(self, d):
		self.list.append(d)

	def rmv(self, d):
		for i in range(len(self.list)):
			if self.list[i] == d:
				self.list[i] = 0
				return True
		return False

class graph:

	def __init__(self, n):
		self.list = [0] * (n + 1)
		for i in range(1, n + 1):
			m = node()
			self.list[i] = m

	def add(self, a, b):
		self.list[a].ad(b)
		self.list[b].ad(a)

	def remove(self, d):
		f = []
		for i in range(1, n + 1):
			if self.list[i] != 0:
				bl = self.list[i].rmv(d)
				if bl:
					f.append(i)
		self.list[d] = 0
		return f
(n, m) = map(int, input().split(' '))
a = [int(i) for i in input().split(' ')]
g = graph(n)
arr = [0] * (n + 1)
for _ in range(m):
	(c, b) = map(int, input().split(' '))
	g.add(c, b)
	arr[c] += a[b - 1]
	arr[b] += a[c - 1]
cnt = 0
ind = -1
while ind != 0:
	ind = find_min(a, n)
	cnt += arr[ind]
	arr[ind] = 0
	h = g.remove(ind)
	for i in range(len(h)):
		arr[h[i]] -= a[ind - 1]
	a[ind - 1] = 0
print(cnt)


import math
inputs = [int(x) for x in input().split()]
n = inputs[0]
m = inputs[1]
part_energy = [''] + [int(x) for x in input().split()]
grid = {i: {'id': i, 'energy_to_remove': 0, 'connected_nodes': set(), 'energy_itself': part_energy[i]} for i in range(1, n + 1)}
for i in range(m):
	inputs = [int(x) for x in input().split()]
	grid[inputs[0]]['energy_to_remove'] += part_energy[inputs[1]]
	grid[inputs[1]]['energy_to_remove'] += part_energy[inputs[0]]
	grid[inputs[0]]['connected_nodes'].add(inputs[1])
	grid[inputs[1]]['connected_nodes'].add(inputs[0])
energy_used = 0
while grid:
	min_item = min(grid.items(), key=lambda item: -item[1]['energy_itself'])[1]
	energy_used += min_item['energy_to_remove']
	for connected_item in min_item['connected_nodes']:
		grid[connected_item]['energy_to_remove'] -= min_item['energy_itself']
		grid[connected_item]['connected_nodes'].remove(min_item['id'])
	del grid[min_item['id']]
print(energy_used)


(n, m) = map(int, input().split())
v = [0] + list(map(int, input().split()))
ans = 0
for _ in range(m):
	(i, j) = map(int, input().split())
	ans += min(v[i], v[j])
print(ans)


import queue
graph = []
value = []
Q = queue.PriorityQueue()
done = []
sumN = []

def inputArray():
	temp = str(input())
	A = temp.split()
	return list(map(int, A))
(n, m) = map(int, input().split())
value = inputArray()
graph = [[] for x in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	graph[a].append(b)
	graph[b].append(a)
input = []
for i in range(n):
	input.append((value[i], i))
input = sorted(input)
ans = 0
done = [0 for x in range(n)]
for i in reversed(input):
	curr = i[1]
	for j in range(len(graph[curr])):
		tp = graph[curr][j]
		if not done[tp]:
			assert value[tp] <= value[curr]
			ans += value[tp]
	done[curr] = True
print(ans)


from __future__ import print_function
import sys
from collections import *
from heapq import *
from functools import *
import re
from itertools import *
INF = float('inf')
NINF = float('-inf')
try:
	input = raw_input
except:
	pass

def read_string():
	return input()

def read_string_line():
	return [x for x in input().split(' ')]

def read_int_line():
	return [int(x) for x in input().split(' ')]

def read_int():
	return int(input())
(n, m) = read_int_line()
ws = read_int_line()
adjs = [set() for _ in range(n + 1)]
for _ in range(m):
	(a, b) = read_int_line()
	adjs[a].add(b)
	adjs[b].add(a)
wsi = [(w, i + 1) for (i, w) in enumerate(ws)]
ws = [0] + ws
wsi.sort(reverse=True)
ans = 0
for (w, i) in wsi:
	ans += sum((ws[x] for x in adjs[i]))
	for x in adjs[i]:
		adjs[x].remove(i)
print('%d' % ans)


from collections import defaultdict
d = defaultdict(int)
(n, m) = map(int, input().split())
v = [int(i) for i in input().split()]
sm = 0
gr = [[v[i], i] for i in range(n)]
gr.sort(reverse=True)
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	sm += min(v[x], v[y])
	if v[x] <= v[y]:
		d[y] += v[x]
	else:
		d[x] += v[y]
sm1 = 0
for i in range(n):
	sm1 += d[gr[i][1]]
print(sm1)


(n, m) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
ans = 0
for _ in range(m):
	(i1, i2) = [int(i) for i in input().split()]
	ans += min(arr[i1 - 1], arr[i2 - 1])
print(ans)


def main():
	(n, m) = map(int, input().split())
	l = [int(i) for i in input().split()]
	ans = 0
	for i in range(m):
		(a, b) = map(int, input().split())
		ans += min(l[a - 1], l[b - 1])
	print(ans)
main()


(n, m) = map(int, input().split(' '))
V = list(map(int, input().split(' ')))
edge = [set() for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split(' '))
	a -= 1
	b -= 1
	edge[a].add(b)
	edge[b].add(a)
L = [[V[i], i] for i in range(n)]
L.sort(key=lambda x: x[0])
ans = 0
for l in L:
	ans += l[0] * len(edge[l[1]])
	for i in edge[l[1]]:
		edge[i].remove(l[1])
	edge[l[1]].clear()
print(ans)


(nVertices, nEdges) = map(int, input().split())
a = list(map(int, input().split()))
ret = 0
for _ in range(nEdges):
	(u, v) = map(lambda x: int(x) - 1, input().split())
	ret += min(a[u], a[v])
print(ret)


def Sol2(cost, cost2, G):
	mk = [0 for _ in range(len(cost))]
	sum = 0
	for node in cost:
		for i in G[node[1]]:
			mk[i] += 1
		c = len(G[node[1]]) - mk[node[1]]
		sum += c * node[0]
	return sum
(n, m) = map(int, input().split())
cost2 = [int(x) for x in input().split()]
cost = [(cost2[i], i) for i in range(len(cost2))]
arist = []
graf = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	arist.append((x - 1, y - 1))
	graf[x - 1].append(y - 1)
	graf[y - 1].append(x - 1)
sort = sorted(cost, key=lambda parameter_list: parameter_list[0], reverse=False)
a = Sol2(sort, cost2, graf)
print(a)


import sys
import itertools
import collections

def rs(x=''):
	return sys.stdin.readline().strip() if len(x) == 0 else input(x).strip()

def ri(x=''):
	return int(rs(x))

def rm(x=''):
	return map(str, rs(x).split())

def rl(x=''):
	return rs(x).split()

def rmi(x=''):
	return map(int, rs(x).split())

def rli(x=''):
	return [int(x) for x in rs(x).split()]

def println(val):
	sys.stdout.write(str(val) + '\n')

def solve(testCase):
	(n, m) = rmi()
	ans = 0
	a = rli()
	for i in range(m):
		(x, y) = rmi()
		x -= 1
		y -= 1
		ans += min(a[x], a[y])
	print(ans)
for _ in range(ri() if 0 else 1):
	solve(_ + 1)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi
import heapq

def I():
	return int(input())

def In():
	return map(int, input().split())

def main():
	try:
		(n, m) = In()
		l = list(In())
		ans = 0
		d = {}
		for x in range(n):
			d[x] = l[x]
		for i in range(m):
			(a, b) = In()
			if d[a - 1] < d[b - 1]:
				ans += d[a - 1]
			else:
				ans += d[b - 1]
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


def main():
	(n, m) = map(int, input().split())
	cur = list(map(int, input().split()))
	tab = []
	graph = [[] for x in range(n)]
	for x in range(n):
		tab.append((cur[x], x))
	for x in range(m):
		(a, b) = map(int, input().split())
		a -= 1
		b -= 1
		graph[a].append(b)
		graph[b].append(a)
	tab.sort()
	tab = tab[::-1]
	v = [0] * n
	s = 0
	for x in range(n):
		for nei in graph[tab[x][1]]:
			if not v[nei]:
				s += cur[nei]
		v[tab[x][1]] = 1
	print(s)
main()


from collections import defaultdict
[n, m] = [int(item) for item in input().split(' ')]
energy = [0] + [int(item) for item in input().split(' ')]
edges = defaultdict(lambda : [])
ans = 0
for item in range(m):
	[a, b] = [int(item) for item in input().split(' ')]
	ans += min(energy[a], energy[b])
print(ans)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
(n, m) = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for _ in range(m):
	(x, y) = map(int, input().split())
	ans += min(v[x - 1], v[y - 1])
print(ans)


def mlt():
	return map(int, input().split())
(x, y) = mlt()
s = [0] + list(mlt())
res = 0
for n in range(y):
	(a, b) = mlt()
	res += min(s[a], s[b])
print(res)


(n, m) = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
sv = [(x + 1, v[x]) for x in range(n)]
v = [0] + v
edges = {i: set() for i in range(1, n + 1)}
for i in range(m):
	(f, t) = [int(x) for x in input().split()]
	edges[f].add(t)
	edges[t].add(f)
ans = 0
sv.sort(key=lambda x: -x[1])
removed = [False] * (n + 1)
for (i, vi) in sv:
	removed[i] = True
	for f in edges[i]:
		if not removed[f]:
			ans += v[f]
print(ans)


(n, m) = map(int, input().split())
energy = list(map(int, input().split()))
mapping = {}
ans = 0
for (index, val) in enumerate(energy):
	mapping[index + 1] = val
for x in range(m):
	z = tuple(map(int, input().split()))
	ans += min(mapping[z[0]], mapping[z[1]])
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
costs = [[int(i)] for i in input().split()]
costs = [costs[j] + [j] for j in range(n)]
costs2 = {x: y for (y, x) in costs}
costs.sort(reverse=True)
connections = {i: [] for i in range(n)}
total = 0
for i in range(m):
	(a, b) = map(int, input().split())
	connections[a - 1].append(b - 1)
	connections[b - 1].append(a - 1)
for i in range(n):
	while connections[costs[i][1]]:
		current = connections[costs[i][1]].pop()
		connections[current].remove(costs[i][1])
		total += costs2[current]
print(total)


(n, m) = map(int, input().split())
v = list(map(int, input().split()))
tot = 0
for i in range(m):
	(x, y) = map(int, input().split())
	if v[x - 1] <= v[y - 1]:
		tot += v[x - 1]
	else:
		tot += v[y - 1]
print(tot)


def destroy():
	(parts, ropes) = map(int, input().split())
	(v, res) = ([int(x) for x in input().split()], 0)
	for i in range(ropes):
		res += min((v[int(x) - 1] for x in input().split()))
	print(res)
destroy()


from collections import defaultdict
(n, m) = list(map(int, input().split()))
v = list(map(int, input().split()))
graph = defaultdict(list)
for i in range(m):
	(x, y) = list(map(int, input().split()))
	graph[x - 1].append(y - 1)
	graph[y - 1].append(x - 1)
nodes = [i for i in range(n)]
nodes.sort(key=lambda x: v[x], reverse=True)
removido = [False for i in range(n)]
cost = 0
for node in nodes:
	removido[node] = True
	for adj in graph[node]:
		if not removido[adj]:
			cost += v[adj]
print(cost)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	(z, x) = map(int, input().split())
	ans += min(a[z - 1], a[x - 1])
print(ans)


def dfs(edges, energy, node, visited):
	stack = [node]
	cost = 0
	while stack:
		curr = stack.pop()
		if curr not in visited:
			visited.add(curr)
			for kid in edges[curr]:
				if kid not in visited:
					cost += min(energy[curr - 1], energy[kid - 1])
					stack.append(kid)
	return cost

def Solve(edges, energy):
	n = len(edges)
	cost = 0
	visited = set()
	for i in range(1, n + 1):
		if i not in visited:
			cost += dfs(edges, energy, i, visited)
	print(cost)

def main():
	(n, m) = map(int, input().split())
	energy = list(map(int, input().split()))
	edges = {}
	for i in range(1, n + 1):
		edges[i] = []
	for i in range(m):
		(a, b) = map(int, input().split())
		edges[a].append(b)
		edges[b].append(a)
	Solve(edges, energy)
main()


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.insert(0, 0)
ans = 0
for i in range(m):
	(x, y) = map(int, input().split())
	ans += min(l[x], l[y])
print(ans)


r = lambda : map(int, input().split())
(n, m) = r()
a = [0] + list(r())
print(sum((min(a[u], a[v]) for (u, v) in (r() for i in range(m)))))


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
ans = 0
for i in ' ' * b:
	(p, q) = map(int, input().split())
	ans += min(s[p - 1], s[q - 1])
print(ans)


(N, M) = [int(i) for i in input().split(' ')]
V = [int(i) for i in input().split(' ')]
answer = 0
for m in range(M):
	(x, y) = [int(i) for i in input().split(' ')]
	answer += min(V[x - 1], V[y - 1])
print(answer)


edges = [int(x) for x in input().split(' ')][1]
arr = [int(x) for x in input().split(' ')]
energy = 0
for i in range(edges):
	t = [int(x) for x in input().split(' ')]
	energy += min(arr[t[0] - 1], arr[t[1] - 1])
print(energy)


nm = list(map(int, input().split(' ')))
w = list(map(int, input().split(' ')))
ans = 0
for x in range(nm[1]):
	d = list(map(int, input().split(' ')))
	ans += min(w[d[0] - 1], w[d[1] - 1])
print(ans)


(n, m) = map(int, input().split())
u = list(map(int, input().split()))
v = list(enumerate(u, 1))
v.sort(key=lambda x: x[1], reverse=True)
(s, u) = (0, [0] + u)
p = [[] for i in range(n + 1)]
for i in range(m):
	(x, y) = map(int, input().split())
	p[x].append(y)
	p[y].append(x)
for (x, f) in v:
	for y in p[x]:
		s += u[y]
	u[x] = 0
print(s)


(n, m) = tuple(map(int, input().split()))
v = list(map(int, input().split()))
ropes = []
links = []
for j in range(n):
	links.append([])
for k in range(m):
	(a, b) = tuple(map(int, input().split()))
	links[a - 1].append(b - 1)
	links[b - 1].append(a - 1)
	ropes.append((a - 1, b - 1))
for i in range(n):
	v[i] = (v[i], i)
v = sorted(v, reverse=True)
out = set([])
res = 0
for j in range(n):
	out.add(v[j][1])
	for i in range(n):
		if not v[i][1] in out and v[i][1] in links[v[j][1]]:
			res += v[i][0]
print(res)


inp = lambda : map(int, input().split())
(n, m) = inp()
a = list(inp())
ans = 0
for i in range(m):
	(v1, v2) = map(int, input().split())
	v1 -= 1
	v2 -= 1
	ans += min(a[v1], a[v2])
print(ans)


(n, m) = [int(a) for a in input().split()]
v = [int(a) for a in input().split()]
adj = [set() for _ in range(n)]
for i in range(m):
	(x, y) = [int(a) for a in input().split()]
	x -= 1
	y -= 1
	adj[x].add(y)
	adj[y].add(x)
totalenergy = 0
for i in range(n):
	attached = list([(x, vv) for (x, vv) in enumerate(v) if adj[x]])
	if not attached:
		break
	(maxx, maxv) = max(attached, key=lambda x: x[1])
	totalenergy += sum([v[y] for y in adj[maxx]])
	for y in adj[maxx]:
		adj[y].remove(maxx)
	adj[maxx].clear()
print(totalenergy)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
import math

def ip():
	return int(sys.stdin.readline())

def sip():
	return input()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
(n, m) = mip()
arr = lip()
count = 0
while m:
	m -= 1
	(a, b) = mip()
	count += min(arr[b - 1], arr[a - 1])
print(count)


INF = 10 ** 10
(n, m) = map(int, input().split())
w = list(([0, a] for a in map(int, input().split())))
summ = 0
adj = [[0] * n for _ in range(n)]
for _ in range(m):
	(x, y) = map(int, input().split())
	adj[x - 1][y - 1] = adj[y - 1][x - 1] = 1
	w[x - 1][0] += w[y - 1][1]
	w[y - 1][0] += w[x - 1][1]
for i in range(n - 1):
	k = w.index(max(w, key=lambda x: (x[1], -x[0])))
	summ += w[k][0]
	for j in range(n):
		if adj[j][k] == 1:
			adj[j][k] = adj[k][j] = 0
			w[j][0] -= w[k][1]
	w[k][0] = INF
	w[k][1] = 0
print(summ)


import math
(n, m) = map(int, input().split())
v = list(map(int, input().split()))
res = 0
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	res += min(v[x], v[y])
print(res)


(n, m) = map(int, input('').split())
weight_list = list(map(int, input('').split()))
vertice_weights = {i: weight_list[i - 1] for i in range(1, n + 1)}
edge_list = []
for i in range(m):
	(start, end) = map(int, input('').split())
	edge_list.append((start, end))
min_energy = 0
for edge in edge_list:
	(start, end) = (edge[0], edge[1])
	if vertice_weights[start] < vertice_weights[end]:
		min_energy += vertice_weights[start]
	else:
		min_energy += vertice_weights[end]
print(min_energy)


import sys
import heapq
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
(n, m) = sp()
a = l()
answer = 0
for i in range(m):
	(u, v) = sp()
	answer += min(a[u - 1], a[v - 1])
out(answer)
exit()


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, m) = get_ints()
	weight = []
	for i in range(n):
		weight.append([])
	arr = get_list()
	ans = 0
	for i in range(m):
		(x, y) = get_ints()
		ans += min(arr[x - 1], arr[y - 1])
	print(ans)


(n, m) = map(int, input().split())
v = [0] + list(map(int, input().split()))
en = 0
for i in range(m):
	(a, b) = map(int, input().split())
	en += min(v[a], v[b])
print(en)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a = [0] + a
count = 0
for i in range(m):
	(x, y) = map(int, input().split())
	count += min(a[x], a[y])
print(count)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def main():
	(n, m) = LI()
	a = LI()
	aa = [LI_() for _ in range(m)]
	r = 0
	for (b, c) in aa:
		r += min(a[b], a[c])
	return r
print(main())


(n, m) = map(int, input().split())
graph = [[] for _ in range(n + 1)]
used = [False] * (n + 1)
energy = [0] + list(map(int, input().split()))
sorted_energies = sorted(map(lambda x: (x[1], x[0]), enumerate(energy)), reverse=True)
result = 0
for _ in range(m):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
for item in sorted_energies:
	if not used[item[1]]:
		used[item[1]] = True
		for adj in graph[item[1]]:
			if not used[adj]:
				result += energy[adj]
print(result)


(n, m) = map(int, input().split())
ve = list(map(int, input().split()))
ans = 0
for i in range(m):
	(c1, c2) = map(int, input().split())
	ans += min(ve[c1 - 1], ve[c2 - 1])
print(ans)


(n, m) = map(int, input().split())
v1 = list(map(int, input().split()))
v = [[w, i] for (i, w) in enumerate(v1)]
v.sort(reverse=True)
d = [set() for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	d[a].add(b)
	d[b].add(a)
ans = 0
for (w, i) in v:
	for j in d[i]:
		ans += v1[j]
		d[j].discard(i)
print(ans)


line = input().split()
n = int(line[0])
m = int(line[1])
line = input().split()
weights = [0] * n
edges = [0] * n
for i in range(n):
	weights[i] = [int(line[i]), i]
	edges[i] = []
for i in range(m):
	line = input().split()
	a = int(line[0]) - 1
	b = int(line[1]) - 1
	edges[a].append(b)
	edges[b].append(a)
sortedWeights = sorted(weights, reverse=True)
ans = 0
removed = []
for element in sortedWeights:
	index = element[1]
	for neighboor in edges[index]:
		if neighboor not in removed:
			ans += weights[neighboor][0]
	removed.append(index)
print(ans)