#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[10000];
int b[10000][2];
int ok[10000];
int ans[10000];
int memo[5001];
int a[6000];
int solve(int i) {
  if (i == n) {
    return 0;
  }
  int &ret = memo[i];
  if (ret != -1) return ret;
  int x1 = 0, x2 = 0;
  x1 = solve(i + 1);
  if (ok[a[i]] == 1 && b[a[i]][0] == i) {
    x2 = ans[a[i]] + solve(b[a[i]][1] + 1);
  }
  return ret = max(x1, x2);
}
int main() {
  memset(memo, -1, sizeof(memo));
  cin >> n;
  for (int i = 0; i < 10000; i++) {
    b[i][0] = 1e9;
    b[i][1] = -1;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v[a[i]].push_back(i);
    b[a[i]][0] = min(b[a[i]][0], i);
    b[a[i]][1] = max(b[a[i]][1], i);
  }
  for (int i = 0; i <= 5000; i++) {
    if (b[i][0] != 1e9 && b[i][1] != -1) {
      int minx = b[i][0], maxx = b[i][1];
      map<int, int> f;
      int temp = 0;
      int yes = 1;
      for (int j = b[i][0]; j <= b[i][1]; j++) {
        f[a[j]]++;
        if (f[a[j]] == 1) {
          temp = temp ^ a[j];
        }
        int u = a[j];
        b[i][1] = max(b[i][1], b[u][1]);
        if (b[u][0] < b[i][0]) yes = 0;
      }
      if (yes) {
        ok[i] = 1;
        ans[i] = temp;
      }
    }
  }
  cout << solve(0);
}
