#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30005;
struct Matrix {
  long long a[3][3];
} T[MAXN * 4];
Matrix operator*(const Matrix &a, const Matrix &b) {
  Matrix c;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) c.a[i][j] = -(1ll << 60);
  for (int i = 0; i < 3; i++)
    for (int k = 0; k < 3; k++)
      for (int j = 0; j < 3; j++)
        c.a[i][j] = max(c.a[i][j], a.a[i][k] + b.a[k][j]);
  return c;
}
pair<long long, long long> W[MAXN], H[MAXN];
int N, Q, P[MAXN], Ref[MAXN];
long long Val[3][MAXN];
void Self(Matrix &a, int p) {
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) a.a[i][j] = -(1ll << 60);
  a.a[1][0] = 0, a.a[2][1] = 0;
  if (P[W[p].second] != H[p].second) a.a[2][2] = Val[0][p];
  a.a[1][2] = Val[1][p];
  a.a[0][2] = Val[2][p];
}
void Build(int l, int r, int jd) {
  if (l == r)
    Self(T[jd], l);
  else {
    int mid = l + r >> 1;
    Build(l, mid, jd << 1), Build(mid + 1, r, jd << 1 | 1);
    T[jd] = T[jd << 1] * T[jd << 1 | 1];
  }
}
void Update(int l, int r, int p, int jd) {
  if (l == r)
    Self(T[jd], l);
  else {
    int mid = l + r >> 1;
    if (p <= mid)
      Update(l, mid, p, jd << 1);
    else
      Update(mid + 1, r, p, jd << 1 | 1);
    T[jd] = T[jd << 1] * T[jd << 1 | 1];
  }
}
int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 1; i <= N; i++) scanf("%lld", &W[i].first), W[i].second = i;
  for (int i = 1; i <= N; i++) scanf("%lld", &H[i].first), H[i].second = i;
  sort(W + 1, W + N + 1), sort(H + 1, H + N + 1);
  for (int i = 1; i <= N; i++) Ref[W[i].second] = i;
  for (int i = 1; i <= N; i++) {
    Val[0][i] = Val[1][i] = Val[2][i] = -(1ll << 60);
    Val[0][i] = W[i].first * H[i].first;
    if (i - 1)
      Val[1][i] = W[i].first * H[i - 1].first + H[i].first * W[i - 1].first;
    if (i - 2) {
      Val[2][i] = H[i].first * W[i - 2].first + H[i - 1].first * W[i].first +
                  H[i - 2].first * W[i - 1].first;
      Val[2][i] = max(Val[2][i], H[i].first * W[i - 1].first +
                                     H[i - 1].first * W[i - 2].first +
                                     H[i - 2].first * W[i].first);
    }
  }
  for (int i = 1; i <= N; i++) P[i] = i;
  Build(1, N, 1);
  for (int i = 1; i <= Q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    swap(P[x], P[y]);
    Update(1, N, Ref[x], 1), Update(1, N, Ref[y], 1);
    printf("%I64d\n", T[1].a[2][2]);
  }
  return 0;
}
