#include <cstdio>
#include <vector>
using namespace std;

typedef long long i64;

int main()
{
	int n;
	vector<i64> as;

	scanf("%d", &n);
	as.resize(n);
	for(int i = 0; i < n; i++) {
		scanf("%lld", &as[i]);
	}

	i64 sum = 0;
	for(auto& a : as) {
		sum = sum ^ a;
	}

	for(auto& a : as) {
		a = a & (~sum);
	}

	i64 maxi = 0;

	for(int b = 62; b >= 0; b--) {

		i64 v = -1;

		for(int i = 0; i < n; i++) {
			if((as[i] & (1LL << b)) != 0) {
				v = as[i];
				break;
			}
		}

		if(v == -1) {
			continue;
		}

		for(int i = 0; i < n; i++) {
			if((as[i] & (1LL << b)) != 0) {
				as[i] = as[i] ^ v;
			}
		}

		maxi = max(maxi ^ v, maxi);
	}

	i64 ans = maxi * 2 + sum;
	printf("%lld\n", ans);

	return 0;
}

#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

int g[10][10];
int f[10][10];

void solve() {
  int M;
  cin >> M;
  int ans = -1;
  int sum = 0;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      int a = i+j;
      g[i][j] = a/10+a%10;
      f[i][j] = a >= 10 ? 2 : 1;
    }
  }

  int amari = 0;
  while (M--) {
    int c, d; cin >> d >> c;

    while (c > 1) {
      if (c%2 == 1) {
        c--;
        ans += f[amari][d];
        amari = g[amari][d];
      }

      c /= 2;
      ans += c * f[d][d];
      d = g[d][d];
    }

    ans += f[amari][d];
    amari = g[amari][d];
  }

  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
