#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
using namespace std;
const long long MXN = 3e5 + 10;
const long long INF = 1e16;
int n, q, x, y;
pair<int, int> A[MXN], B[MXN];
int match[MXN];
long long dp[3][MXN], now;
long long Cal(const int &i, const int &j) {
  if (match[A[i].second] == B[j].second) return -INF;
  return 1ll * A[i].first * B[j].first;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> B[i].first;
    B[i].second = i;
  }
  iota(match + 1, match + n + 1, 1);
  sort(A + 1, A + n + 1, greater<pair<int, int>>());
  sort(B + 1, B + n + 1, greater<pair<int, int>>());
  while (q--) {
    cin >> x >> y;
    swap(match[x], match[y]);
    dp[0][1] = Cal(1, 1), dp[1][1] = 0;
    dp[0][2] = max(Cal(1, 1) + Cal(2, 2), Cal(1, 2) + Cal(2, 1));
    dp[1][2] = Cal(1, 1), dp[2][2] = 0;
    for (int i = 3; i <= n; i++) {
      dp[1][i] = dp[0][i - 1], dp[2][i] = dp[1][i - 1];
      now = max({Cal(i, i - 1) + Cal(i - 1, i - 2) + Cal(i - 2, i),
                 Cal(i, i - 2) + Cal(i - 1, i) + Cal(i - 2, i - 1),
                 Cal(i, i - 2) + Cal(i - 1, i - 1) + Cal(i - 2, i)});
      dp[0][i] = max({Cal(i, i) + dp[0][i - 1],
                      Cal(i, i - 1) + Cal(i - 1, i) + dp[1][i - 1],
                      now + dp[2][i - 1]});
    }
    cout << dp[0][n] << '\n';
  }
  return 0;
}
