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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main{
	
	public static void main(String args[]) throws IOException{
		new Main().mains();
	}
	
	public int P[],move_range[],throw_range[],ans,name[][];
	public boolean F[];
	
	int sta_num(int statue){
		int ret = (P[1] - 1) + (P[2] - 1) * 42 + (P[3] - 1) * 42 * 42;
		return ret + statue * 42 * 42 * 42;
	}
	
	int num(int a, int b){
		if (b == 0) return (a == 1) ? (2) : (1);
		return (a == 3) ? (2) : (3);
	}
	
	void DFS(int statue){
		ans = Math.max(ans, Math.max(Math.max(P[3], P[1]), P[2]));
		if (F[sta_num(statue)] == true) return;
		F[sta_num(statue)] = true;
		int foru[] = new int[4];
		/*int check[] = new int[4];
		for (int i = 1; i <= 3; i ++) check[i] = P[i];*/
		boolean be_throwed[] = new boolean[4];
		for (int mv = 1; mv <= 3; mv ++)
			be_throwed[mv] = false;
		for (int mv = 1; mv <= 3; mv ++){
			foru[mv] = (statue >> (3 + (mv - 1) * 2)) % 4;
			if (foru[mv] >= 1 && foru[mv] <= 2)
				be_throwed[num(mv, foru[mv] - 1)] = true;
		}
		for (int i = 1; i <= 3; i ++)
			if ((statue & (1 << (i - 1))) == 0 && (foru[i] == 0 || foru[i] == 3)){
				for (int step = -move_range[i]; step <= move_range[i]; step ++){
					if (step + P[i] < 1) continue;
					boolean could = true;
					for (int j = 1; j <= 3; j ++)
						if (step + P[i] == P[j])
							could = false;
					if (could == false) continue;
					P[i] += step;
					DFS(statue | (1 << (i - 1)));
					P[i] -= step;
				}
			}
		for (int i = 1; i <= 3; i ++){
			for (int j = 1; j <= 3; j ++)
				if (i != j && Math.abs(P[i] - P[j]) == 1 && be_throwed[j] == false && foru[i] == 0 && be_throwed[i] == false){
					int diff = 6 - i - j;
					int temp[] = new int[4],newsta = statue | ((1 << ((2 * i - 2) + 3)) * (name[i][j] + 1));
					temp[1] = P[1]; temp[2] = P[2]; temp[3] = P[3];
					P[j] = P[i];
					if (be_throwed[diff] == true) P[diff] = P[i];
					DFS(newsta);
					P[1] = temp[1]; P[2] = temp[2]; P[3] = temp[3];
				}
			if (be_throwed[i] == false && foru[i] >= 1 && foru[i] <= 2){
				int j = num(i, foru[i] - 1), diff = 6 - i - j;
				int xor = ((1 << (2 * i - 2) + 3) * (foru[i]));
				for (int step = -throw_range[i]; step <= throw_range[i]; step ++) if (step != 0){
					int temp[] = new int[4],newsta = (statue ^ xor) | (3 * (1 << ((2 * i - 2) + 3)));
					temp[1] = P[1]; temp[2] = P[2]; temp[3] = P[3];
					P[j] = P[i] + step;
					if (be_throwed[diff] == true) P[diff] = P[i] + step;
					DFS(newsta);
					P[1] = temp[1]; P[2] = temp[2]; P[3] = temp[3];
				}
			}
		}
	}
	
	public void solve() throws IOException{
		P = new int[4];
		move_range = new int[4];
		throw_range = new int[4];
		name = new int[5][5];
		name[1][3] = name[2][3] = name[3][2] = 1;
		F = new boolean[(42 * 8) * (42 * 8) * (42 * 8) + 100];
		for (int i = 1; i <= 3; i ++){
			P[i] = nextInt();
			move_range[i] = nextInt();
			throw_range[i] = nextInt();
		}
		DFS(0);
		out.println(ans);
	}
	
	void mains() throws IOException{
		reader = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(new OutputStreamWriter(System.out));
		tokenizer = null;
		//File fin = new File("a.in");
		//reader = new BufferedReader(new InputStreamReader(new FileInputStream(fin)));
		//out = new PrintWriter("a.out");
		solve();
		reader.close();
		out.flush();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter out;
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	
}