#include <bits/stdc++.h>
using namespace std;
const int Maxn = 31000;
long long f[Maxn];
long long best1[Maxn];
long long best2[Maxn];
long long best3[Maxn];
long long best4[Maxn];
int a[Maxn];
int b[Maxn];
int pos[Maxn];
int ida[Maxn];
int idb[Maxn];
int no[Maxn];
int N, M;
bool Cmpa(int A, int B) { return a[A] < a[B]; }
bool Cmpb(int A, int B) { return b[A] < b[B]; }
void calc(int i) {
  best1[i] = best2[i] = best3[i] = best4[i] = -100000000000000000LL;
  if (no[ida[i]] != idb[i]) best1[i] = (long long)a[ida[i]] * b[idb[i]];
  if (i > 1) {
    int per[2];
    per[0] = 1;
    per[1] = 0;
    do {
      if (no[ida[i]] != idb[i - per[0]] && no[ida[i - 1]] != idb[i - per[1]]) {
        best2[i] =
            max(best2[i], (long long)a[ida[i]] * b[idb[i - per[0]]] +
                              (long long)a[ida[i - 1]] * b[idb[i - per[1]]]);
      }
    } while (next_permutation(per, per + 2));
  }
  if (i > 2) {
    int per[3];
    per[0] = 0;
    per[1] = 1;
    per[2] = 2;
    do {
      if (no[ida[i]] != idb[i - per[0]] && no[ida[i - 1]] != idb[i - per[1]] &&
          no[ida[i - 2]] != idb[i - per[2]]) {
        best3[i] =
            max(best3[i], (long long)a[ida[i]] * b[idb[i - per[0]]] +
                              (long long)a[ida[i - 1]] * b[idb[i - per[1]]] +
                              (long long)a[ida[i - 2]] * b[idb[i - per[2]]]);
      }
    } while (next_permutation(per, per + 3));
  }
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= N; ++i) scanf("%d", &b[i]);
  for (int i = 1; i <= N; ++i) no[i] = ida[i] = idb[i] = i;
  sort(ida + 1, ida + N + 1, Cmpa);
  sort(idb + 1, idb + N + 1, Cmpb);
  for (int i = 1; i <= N; ++i) pos[ida[i]] = i;
  for (int i = 1; i <= N; ++i) calc(i);
  for (int ii = 0; ii < M; ++ii) {
    int x, y;
    scanf("%d%d", &x, &y);
    swap(no[x], no[y]);
    int xx = pos[x];
    int yy = pos[y];
    f[0] = 0;
    for (int i = 1; i <= N; ++i) {
      if ((i - 3 <= xx && i >= xx) || (i - 3 <= yy && i >= yy)) calc(i);
      f[i] = -100000000000000000LL;
      f[i] = f[i - 1] + best1[i];
      if (i > 1) f[i] = max(f[i], f[i - 2] + best2[i]);
      if (i > 2) f[i] = max(f[i], f[i - 3] + best3[i]);
    }
    printf("%I64d\n", f[N]);
  }
  return 0;
}
