#include <bits/stdc++.h>
using namespace std;
const int N = 30000 + 10;
const long long inf = 1e18 + 10;
pair<long long, long long> w[N], h[N];
long long own[N], dp[N];
long long Pow(int x, int y) {
  if (own[w[x].second] == h[y].second) return -inf;
  return w[x].first * h[y].first;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> w[i].first, w[i].second = i;
  for (int i = 1; i <= n; i++) cin >> h[i].first, h[i].second = i;
  for (int i = 1; i <= n; i++) own[i] = i;
  sort(w + 1, w + n + 1);
  sort(h + 1, h + n + 1);
  while (q--) {
    int x, y;
    cin >> x >> y;
    swap(own[x], own[y]);
    dp[1] = Pow(1, 1);
    dp[2] = max(Pow(1, 1) + Pow(2, 2), Pow(1, 2) + Pow(2, 1));
    for (int i = 3; i <= n; i++) {
      dp[i] = dp[i - 1] + Pow(i, i);
      dp[i] = max(dp[i], dp[i - 2] + Pow(i - 1, i) + Pow(i, i - 1));
      dp[i] = max(
          dp[i], dp[i - 3] + Pow(i - 1, i - 2) + Pow(i, i - 1) + Pow(i - 2, i));
      dp[i] = max(
          dp[i], dp[i - 3] + Pow(i, i - 2) + Pow(i - 2, i - 1) + Pow(i - 1, i));
      dp[i] = max(
          dp[i], dp[i - 3] + Pow(i, i - 2) + Pow(i - 1, i - 1) + Pow(i - 2, i));
    }
    cout << dp[n] << '\n';
  }
  return 0;
}
