Problem: You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 1 from the end of half-line, i. e. 1, 2, 3 and so on. The distance between the positions is the absolute difference between the respective numbers. 

Laharl, Etna and Flonne occupy some positions on the half-line and they want to get to the position with the largest possible number. They are originally placed in different positions. 

Each of the characters can perform each of the following actions no more than once: 

  * Move a certain distance. 
  * Grab another character and lift him above the head. 
  * Throw the lifted character a certain distance. 



Each character has a movement range parameter. They can only move to free positions, assuming that distance between those positions doesn't exceed the movement range. 

One character can lift another character if the distance between the two characters equals 1, and no one already holds that another character. We can assume that the lifted character moves to the same position as the person who has lifted him, and the position in which he stood before becomes free. A lifted character cannot perform any actions and the character that holds him cannot walk. 

Also, each character has a throwing range parameter. It is the distance at which this character can throw the one lifted above his head. He can only throw a character to a free position, and only when there is a lifted character. 

We accept the situation when one person grabs another one who in his turn has the third character in his hands. This forms a "column" of three characters. For example, Laharl can hold Etna while Etna holds Flonne. In this case, Etna and the Flonne cannot perform any actions, and Laharl can only throw Etna (together with Flonne) at some distance. 

Laharl, Etna and Flonne perform actions in any order. They perform actions in turns, that is no two of them can do actions at the same time.

Determine the maximum number of position at least one of the characters can reach. That is, such maximal number x so that one of the characters can reach position x.

Input

The first line contains three integers: Laharl's position, his movement range and throwing range. The second and the third lines describe Etna's and Flonne's parameters correspondingly in the similar form. It is guaranteed that the three characters occupy distinct positions. All numbers in the input are between 1 and 10, inclusive.

Output

Print a single number — the maximum ordinal number of position which either Laharl, Etna or Flonne can reach.

Examples

Input

9 3 3
4 3 1
2 3 3


Output

15

Note

Let us explain how to reach position 15 in the sample.

Initially Laharl occupies position 9, Etna — position 4 and Flonne — position 2.

First Laharl moves to position 6.

Then Flonne moves to position 5 and grabs Etna.

Laharl grabs Flonne and throws to position 9.

Flonne throws Etna to position 12.

Etna moves to position 15.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct Counter {
  static int k;
  Counter() { k++; }
  ~Counter() { k--; }
};
int Counter::k = 0;
template <typename T>
void pr(const string &name, T t) {
  cout << name << " = " << t << endl;
}
template <typename T, typename... Types>
void pr(const string &names, T t, Types... rest) {
  auto comma_pos = names.find(',');
  cout << names.substr(0, comma_pos) << " = " << t << ", ";
  auto next_name_pos = names.find_first_not_of(" \t\n", comma_pos + 1);
  pr(string(names, next_name_pos), rest...);
}
void mod(long long &a, long long b) {
  a %= b;
  if (a < 0) a += b;
}
const long long MOD = 1000000007;
struct State {
  vector<int> pos, used, up;
  State(vector<int> p1, vector<int> p2, vector<int> p3) {
    pos = p1, used = p2, up = p3;
  }
  friend bool operator<(State s1, State s2) {
    if (s1.pos != s2.pos) return s1.pos < s2.pos;
    if (s1.used != s2.used) return s1.used < s2.used;
    return s1.up < s2.up;
  }
};
int Move[3], Throw[3];
queue<State> Q;
unordered_set<int> Reach;
bool free(State &st, int p) {
  for (int i = (0); i <= (2); i++)
    if (st.up[0] != i && st.up[1] != i && st.up[2] != i && st.pos[i] == p)
      return false;
  return true;
}
int getHash(State &st) {
  long long h = 1;
  for (int i = (0); i <= (2); i++) {
    h = 33 * h + 37 * st.pos[i];
    h %= MOD;
  }
  for (int i = (0); i <= (2); i++) {
    h = 23 * h + 17 * st.used[i];
    h %= MOD;
  }
  for (int i = (0); i <= (2); i++) {
    h = 71 * h + 7 * st.up[i];
    h %= MOD;
  }
  return h;
}
int main() {
  vector<int> p(3, 0);
  vector<int> h = {-1, -1, -1};
  vector<int> u = {0, 0, 0};
  for (int i = (0); i <= (2); i++) cin >> p[i] >> Move[i] >> Throw[i];
  State str(p, u, h);
  Reach.insert(getHash(str));
  Q.push(State(p, u, h));
  int ans = 0;
  while (!Q.empty()) {
    State st = Q.front();
    Q.pop();
    int maxReach = -1;
    for (int i = (0); i <= (2); i++) {
      int m = st.pos[i];
      if (!(st.used[i] & 1)) m += Move[i];
      for (int j = (0); j <= (2); j++)
        if (i != j && !(st.used[j] & 2)) m += Throw[j] + 1;
      maxReach = max(maxReach, m);
    }
    if (maxReach <= ans) continue;
    for (int i = (0); i <= (2); i++) ans = max(ans, st.pos[i]);
    for (int i = (0); i <= (2); i++)
      if (!(st.used[i] & 1))
        for (int p = (max(st.pos[i] - Move[i], 1)); p <= (st.pos[i] + Move[i]);
             p++)
          if (st.up[i] < 0 && st.up[0] != i && st.up[1] != i && st.up[2] != i &&
              free(st, p)) {
            int prev = st.pos[i];
            st.pos[i] = p;
            st.used[i]++;
            if (Reach.find(getHash(st)) == Reach.end()) {
              Reach.insert(getHash(st));
              Q.push(st);
            }
            st.used[i]--;
            st.pos[i] = prev;
          }
    for (int i = (0); i <= (2); i++)
      if (!(st.used[i] & 2))
        for (int p = (min(st.pos[i] - Throw[i], 1));
             p <= (st.pos[i] + Throw[i]); p++) {
          if (st.up[i] >= 0 && st.up[0] != i && st.up[1] != i &&
              st.up[2] != i && free(st, p)) {
            int prev[3];
            for (int k = (0); k <= (2); k++) prev[k] = st.pos[k];
            int ph = st.up[i];
            st.pos[st.up[i]] = p;
            st.up[i] = -1;
            st.used[i] += 2;
            if (Reach.find(getHash(st)) == Reach.end()) {
              Reach.insert(getHash(st));
              Q.push(st);
            }
            st.used[i] -= 2;
            for (int k = (0); k <= (2); k++) st.pos[k] = prev[k];
            st.up[i] = ph;
          }
        }
    for (int i = (0); i <= (2); i++)
      if (!(st.used[i] & 4))
        for (int j = (0); j <= (2); j++) {
          if (abs(st.pos[j] - st.pos[i]) == 1 && st.up[0] != j &&
              st.up[1] != j && st.up[2] != j && st.up[0] != i &&
              st.up[1] != i && st.up[2] != i) {
            st.up[i] = j;
            st.used[i] += 4;
            if (Reach.find(getHash(st)) == Reach.end()) {
              Reach.insert(getHash(st));
              Q.push(st);
            }
            st.used[i] -= 4;
            st.up[i] = -1;
          }
        }
  }
  cout << ans;
}