Mex table generation There is a table (the matrix one, not the one in your kitchen) called the "mex table". It has a left-top cell, at coordinates (0,0), but extends to infinity rightwards and downwards. The x-coordinate increases to the right and the y-coordinate increases downwards.

Every cell has a value >=0, and the cell at (0,0) has the value 0. The value of any other cell is defined as the lowest integer, >=0, which does not occur directly above it or directly to the left of it.

The start of the mex table looks like this:

+---+---+---+---+---+-
| 0 | 1 | 2 | 3 | 4 | ..
+---+---+---+---+---+-
| 1 | 0 | 3 | 2 | 5 | ..
+---+---+---+---+---+-
| 2 | 3 | 0 | 1 | ..
+---+---+---+---+-
| 3 | 2 | 1 | ..
+---+---+---+-
| 4 | 5 | ..
+---+---+-
| : | : | \


So, for example, the cell at (2,1) is 3 because 0 occurs left of it, 1 occurs left of it and 2 occurs above the cell. The cell at (3,1) is 2, however, because in the part of the row directly to the left of (3,1) and the part of the column directly above (3,1), 0, 1 and 3 occur, but 2 doesn't.

Objective: Print, to standard output, the number in the cell at (x,y) given two integers, both >=0, on standard input, space-separated and newline-terminated.

Thunderbirds are GO!

(This is derived from a question from the national finals of the Dutch Informatics Olympiad of some time ago.)
GolfScript (2 chars)

~^


This is familiar to anyone who knows anything at all about combinatorial game theory.