class Permutations {
  static def list = []
  public static void printPermutation(char[] a, int startIndex, int endIndex) {
    if (startIndex == endIndex)
        list << ((new String(a)) as Integer)
    else {
        for (int x = startIndex; x < endIndex; x++) {
            swap(a, startIndex, x)
            printPermutation(a, startIndex + 1, endIndex)
            swap(a, startIndex, x)
        }
    }
  }
  private static void swap(char[] a, int i, int x) {
    char t = a[i]
    a[i] = a[x]
    a[x] = t
  }

}
def n = 7876541
def cArray = n.toString().toCharArray()
Permutations.printPermutation(cArray, 0, cArray.size())
println Permutations.list.findAll { it.mod(2) == 0}?.max()