import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int hc (int a, int b, int c) {
  return (a * 256 + b) * 256 + c;
}

import std.container;
alias Q = DList!int;

void main() {
  int a, b, c;
  readf (" %d %d %d", &a, &b, &c);
  auto q = new Q ();
  int[int] d;
  int s = hc (a, b, c);
  d[s] = 0;
  q.insertBack (s);
  while (!q.empty) {
    auto i = q.front;
    q.removeFront ();
    int nd = d[i] + 1;
    c = i & 255;
    i >>= 8;
    b = i & 255;
    a = i >> 8;
    foreach (t; [ tuple (a + 1, b + 1, c),
                  tuple (a, b + 1, c + 1),
                  tuple (a + 1, b, c + 1),
                  tuple (a + 2, b, c),
                  tuple (a, b + 2, c),
                  tuple (a, b, c + 2)]) {
      auto j = hc (t[0], t[1], t[2]);
      if (t[0] == t[1] && t[1] == t[2]) {
        writeln (nd);
        return;
      }
      if (! (j in d)) {
        q.insertBack (j);
        d[j] = nd;
      }
    }
  }
  
}
