//KZNS
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
//
ifstream fin ("energynet.in");
ofstream fout ("energynet.out");
const int Nmax = 1003;
//
int N, M;
int A[Nmax], B[Nmax];
vector<int> gp[Nmax];
vector<int> bmax[Nmax];
bool ex[Nmax] = {0};
int mx[Nmax][2] = {0};
class poi {
public:
inline bool operator () (int a, int b) {
return A[a] < A[b];
}
};
priority_queue<int, vector<int>, poi> ls;
int u1, u2;
vector<pair<int, int> > uls;
//
void fir() {
fin >> N >> M;
for (int i = 1; i <= N; i++)
fin >> A[i];
for (int i = 1; i <= N; i++)
fin >> B[i];
int a, b;
for (int i = 0; i < M; i++) {
fin >> a >> b;
gp[a].push_back(b);
}
}
void ctmx(int x) {
int a = 0, b = 0;
for (int i = 0; i < gp[x].size(); i++) {
if (!ex[gp[x][i]]) {
if (A[gp[x][i]] > a) {
a = A[gp[x][i]];
b = gp[x][i];
}
}
}
mx[x][0] = a;
mx[x][1] = b;
bmax[b].push_back(x);
}
void cxxx(int x) {
int a = 0, b = 0;
for (int i = 0; i < gp[x].size(); i++) {
if (!ex[gp[x][i]]) {
if (A[gp[x][i]] > a) {
a = A[gp[x][i]];
b = gp[x][i];
}
}
}
u1 = a;
u2 = b;
}
//
int main() {
fir();
int edd = 0;
for (int i = 1; i <= N; i++) {
ctmx(i);
edd += mx[i][0];
ls.push(i);
}
int u, ued;
while (!ls.empty()) {
uls.clear();
u = ls.top();
ls.pop();
ex[u] = true;
ued = edd;
ued -= A[u]*bmax[u].size();
ued += B[u];
for (int i = 0; i < bmax[u].size(); i++) {
cxxx(bmax[u][i]);
ued += u1;
uls.push_back(make_pair(u2, bmax[u][i]));
}
if (ued < edd) {
edd = ued;
for (int i = 0; i < uls.size(); i++)
bmax[uls[i].first].push_back(uls[i].second);
}
else {
ex[u] = false;
}
}
fout << edd;
return 0;
}
//UWBH