#include <iostream>
#include <cassert>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define int long long
#define pii pair<int, int>
#define eb emplace_back
#define F first
#define S second
#define test(x) cout << "Test: " << x << '\n'
#define lowbit(x) (x & -x)
#define debug puts("qwq");
#define open(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define close fclose(stdin);fclose(stdout);
namespace FastIO {
template <typename T = int>
inline T read() {
T s = 0, w = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') w = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
return s * w;
}
template <typename T>
inline void read(T &s) {
s = 0;
int w = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') w = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
s = s * w;
}
template <typename T, typename... Arp> inline void read(T &x, Arp &...arp) {
read(x), read(arp...);
}
template <typename T>
inline void write(T x, char ch) {
if (x < 0) x = -x, putchar('-');
static char stk[25];
int top = 0;
do {
stk[top++] = x % 10 + '0', x /= 10;
} while (x);
while (top) putchar(stk[--top]);
putchar(ch);
return;
}
template <typename T>
inline void smax(T &x, T y) {
if (x < y) x = y;
}
template <typename T>
inline void smin(T &x, T y) {
if (x > y) x = y;
}
void quit() {
exit(0);
}
} using namespace FastIO;
int n, m, s, t;
const int N = 1e4 + 19, M = 1e5 + 19, inf = 1e7;
int head[M], nxt[M], w[M], edge[M], tot = 1, vis[N], dis[M], from[N], a[N], maxflow, b[N], ans;
void add(int u, int v, int z) {
edge[++tot] = v;
w[tot] = z;
nxt[tot] = head[u];
head[u] = tot;
}
void more(int u, int v, int z) { add(u, v, z), add(v, u, 0); }
bool find_path() {
for (int i = 1; i <= 2 * n + 2; ++i) vis[i] = dis[i] = 0;
queue<int> q;
q.push(s);
dis[s] = 1e9;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = head[u]; i; i = nxt[i]) {
int v = edge[i];
if (w[i] && !vis[v]) {
dis[v] = min(dis[u], w[i]);
from[v] = i;
vis[v] = 1;
if (v == t) return 1;
q.push(v);
}
}
}
return 0;
}
void get_path() {
int u = t; maxflow += dis[t];
while (u ^ s) {
int v = from[u];
w[v] -= dis[t];
w[v ^ 1] += dis[t];
u = edge[v ^ 1];
}
}
signed main() {
read(n, m); s = n * 2 + 2, t = n * 2 + 1;
for (int i = 1; i <= n; ++i) read(a[i]);
for (int i = 1; i <= n; ++i) ans += abs(b[i] = read());
for (int i = 1; i <= n; ++i) {
more(i, i + n, inf);
if (b[i] < 0) more(s, i, b[i] * -2);
else more(i + n, t, b[i] * 2);
}
for (int i = 1, u, v; i <= m; ++i) {
read(u, v);
more(u + n, v, inf);
more(v + n, u, inf);
}
while (find_path()) get_path();
printf("%lld\n", ans - maxflow);
return 0;
}