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.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {

    public static final int MAX = 43 * 43 * 43 * (1 << 10);
    private List<Integer> q;
    private boolean[] was;
    private int[] pos;
    private int[] move;
    private int[] thr;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        pos = new int[3];
        move = new int[3];
        thr = new int[3];
        for (int i = 0; i < 3; ++i) {
            pos[i] = in.nextInt();
            move[i] = in.nextInt();
            thr[i] = in.nextInt();
        }

        was = new boolean[MAX];
        int st = compressState(pos[0], pos[1], pos[2], 0, 0, 0, 0, 0, 0);
        was[st] = true;

        q = new LinkedList<Integer>();
        q.add(st);
        int best = 0;
        while (!q.isEmpty()) {
            decompress(q.get(0));
            q.remove(0);
            int p1 = statePos1;
            int p2 = statePos2;
            int p3 = statePos3;
            best = Math.max(best, p1);
            best = Math.max(best, p2);
            best = Math.max(best, p3);

            int w1 = stateWas1;
            int w2 = stateWas2;
            int w3 = stateWas3;

            int s1 = statePick1;
            int s2 = statePick2;
            int s3 = statePick3;

            // try step
            if (w1 == 0 && s2 != 1 && s3 != 1 && (s1 == 0 || s1 == 3)) {
                for (int i = -move[0]; i <= move[0]; ++i) {
                    int p = p1 + i;
                    if (p != p2 && p != p3 && p > 0) {
                        int nst = compressState(p, p2, p3, 1, w2, w3, s1, s2, s3);
                        updateQueue(nst);
                    }
                }
            }
            if (w2 == 0 && s1 != 1 && s3 != 2 && (s2 == 0 || s2 == 3)) {
                for (int i = -move[1]; i <= move[1]; ++i) {
                    int p = p2 + i;
                    if (p != p1 && p != p3 && p > 0) {
                        int nst = compressState(p1, p, p3, w1, 1, w3, s1, s2, s3);
                        updateQueue(nst);
                    }
                }
            }
            if (w3 == 0 && s1 != 2 && s2 != 2 && (s3 == 0 || s3 == 3)) {
                for (int i = -move[2]; i <= move[2]; ++i) {
                    int p = p3 + i;
                    if (p != p1 && p != p2 && p > 0) {
                        int nst = compressState(p1, p2, p, w1, w2, 1, s1, s2, s3);
                        updateQueue(nst);
                    }
                }
            }

            // try pick up 1->2
            if (s1 == 0 && Math.abs(p1 - p2) == 1 && s2 != 1 && s3 != 1 && s3 != 2) {
                int np3 = p3;
                if (s2 == 2) {
                    np3 = p1;
                }
                int nst = compressState(p1, p1, np3, w1, w2, w3, 1, s2, s3);
                updateQueue(nst);
            }

            // try pick up 2->1
            if (s2 == 0 && Math.abs(p2 - p1) == 1 && s3 != 1 && s1 != 1 && s3 != 2) {
                int np3 = p3;
                if (s1 == 2) {
                    np3 = p2;
                }
                int nst = compressState(p2, p2, np3, w1, w2, w3, s1, 1, s3);
                updateQueue(nst);
            }


            // try pick up 1->3
            if (s1 == 0 && Math.abs(p1 - p3) == 1 && s2 != 1 && s3 != 1 && s2 != 2) {
                int np2 = p2;
                if (s3 == 2) {
                    np2 = p1;
                }
                int nst = compressState(p1, np2, p1, w1, w2, w3, 2, s2, s3);
                updateQueue(nst);
            }
            // try pick up 3->1
            if (s3 == 0 && Math.abs(p3 - p1) == 1 && s2 != 1 && s1 != 2 && s2 != 2) {
                int np2 = p2;
                if (s1 == 1) {
                    np2 = p3;
                }
                int nst = compressState(p3, np2, p3, w1, w2, w3, s1, s2, 1);
                updateQueue(nst);
            }

            // try pick up 2->3
            if (s2 == 0 && Math.abs(p2 - p3) == 1 && s1 != 1 && s3 != 2 && s1 != 2) {
                int np1 = p1;
                if (s3 == 1) {
                    np1 = p2;
                }
                int nst = compressState(np1, p2, p2, w1, w2, w3, s1, 2, s3);
                updateQueue(nst);
            }

            // try pick up 3->2
            if (s3 == 0 && Math.abs(p3 - p2) == 1 && s1 != 1 && s1 != 2 && s2 != 2) {
                int np1 = p1;
                if (s2 == 1) {
                    np1 = p3;
                }
                int nst = compressState(np1, p3, p3, w1, w2, w3, s1, s2, 2);
                updateQueue(nst);
            }


            // throw 1->2
            if (s1 == 1) {
                for (int delta = -thr[0]; delta <= thr[0]; ++delta) {
                    int npos = p1 + delta;
                    if (npos > 0 && p2 != npos && p3 != npos) {
                        int nst;
                        if (s2 == 2) {
                            nst = compressState(p1, npos, npos, w1, w2, w3, 3, s2, s3);
                        } else {
                            nst = compressState(p1, npos, p3, w1, w2, w3, 3, s2, s3);
                        }
                        updateQueue(nst);
                    }
                }
            }

            // throw 1->3
            if (s1 == 2) {
                for (int delta = -thr[0]; delta <= thr[0]; ++delta) {
                    int npos = p1 + delta;
                    if (npos > 0 && p2 != npos && p3 != npos) {
                        int nst;
                        if (s3 == 2) {
                            nst = compressState(p1, npos, npos, w1, w2, w3, 3, s2, s3);
                        } else {
                            nst = compressState(p1, p2, npos, w1, w2, w3, 3, s2, s3);
                        }
                        updateQueue(nst);
                    }
                }
            }

            // throw 2->1
            if (s2 == 1) {
                for (int delta = -thr[1]; delta <= thr[1]; ++delta) {
                    int npos = p2 + delta;
                    if (npos > 0 && p1 != npos && p3 != npos) {
                        int nst;
                        if (s1 == 2) {
                            nst = compressState(npos, p2, npos, w1, w2, w3, s1, 3, s3);
                        } else {
                            nst = compressState(npos, p2, p3, w1, w2, w3, s1, 3, s3);
                        }
                        updateQueue(nst);
                    }
                }
            }

            // throw 2->3
            if (s2 == 2) {
                for (int delta = -thr[1]; delta <= thr[1]; ++delta) {
                    int npos = p2 + delta;
                    if (npos > 0 && p1 != npos && p3 != npos) {
                        int nst;
                        if (s3 == 1) {
                            nst = compressState(npos, p2, npos, w1, w2, w3, s1, 3, s3);
                        } else {
                            nst = compressState(p1, p2, npos, w1, w2, w3, s1, 3, s3);
                        }
                        updateQueue(nst);
                    }
                }
            }

            // throw 3->1
            if (s3 == 1) {
                for (int delta = -thr[2]; delta <= thr[2]; ++delta) {
                    int npos = p3 + delta;
                    if (npos > 0 && p1 != npos && p2 != npos) {
                        int nst;
                        if (s1 == 1) {
                            nst = compressState(npos, npos, p3, w1, w2, w3, s1, s2, 3);
                        } else {
                            nst = compressState(npos, p2, p3, w1, w2, w3, s1, s2, 3);
                        }
                        updateQueue(nst);
                    }
                }
            }

            // throw 3->2
            if (s3 == 2) {
                for (int delta = -thr[2]; delta <= thr[2]; ++delta) {
                    int npos = p3 + delta;
                    if (npos > 0 && p1 != npos && p2 != npos) {
                        int nst;
                        if (s2 == 1) {
                            nst = compressState(npos, npos, p3, w1, w2, w3, s1, s2, 3);
                        } else {
                            nst = compressState(p1, npos, p3, w1, w2, w3, s1, s2, 3);
                        }
                        updateQueue(nst);
                    }
                }
            }
        }
        out.println(best);
    }

    void updateQueue(int st) {
        if (!was[st]) {
            was[st] = true;
            q.add(st);
        }
    }

    int statePos1, statePos2, statePos3;
    int stateWas1, stateWas2, stateWas3;
    int statePick1, statePick2, statePick3;

    int compressState(int p1, int p2, int p3, int was1, int was2, int was3, int pick1, int pick2, int pick3) {
        int x1 = (was1 | (pick1 << 1));
        int x2 = (was2 | (pick2 << 1));
        int x3 = (was3 | (pick3 << 1));
        int n = p1 * 43 * 43 + p2 * 43 + p3;
        n <<= 9;
        n |= x1;
        x2 <<= 3;
        n |= x2;
        x3 <<= 6;
        n |= x3;
        return n;
    }

    void decompress(int st) {
        int x1 = (st & 7);
        st >>= 3;
        int x2 = (st & 7);
        st >>= 3;
        int x3 = (st & 7);
        st >>= 3;
        statePos3 = st % 43;
        st /= 43;
        statePos2 = st % 43;
        st /= 43;
        statePos1 = st;

        stateWas1 = (x1 & 1);
        stateWas2 = (x2 & 1);
        stateWas3 = (x3 & 1);
        x1 >>= 1;
        x2 >>= 1;
        x3 >>= 1;
        statePick1 = x1;
        statePick2 = x2;
        statePick3 = x3;
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}