#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t meals[3];
  cin >> meals[0] >> meals[1] >> meals[2];
  int64_t days = max(meals[0], max(meals[1], meals[2]));
  int64_t z = 0;
  int64_t missed = INT64_MAX;
  for (int i = 0; i < 3; i++) {
    int64_t a[3];
    for (int j = 0; j < 3; j++) a[j] = meals[(i + j) % 3];
    missed = min(missed, days - a[0] + days - a[1] + days - a[2]);
    missed = min(missed, days - a[0] + days - a[1] + max(days - 1 - a[2], z));
    missed = min(missed, days - a[0] + max(days - 1 - a[1], z) +
                             max(days - 1 - a[2], z));
  }
  cout << missed << "\n";
}
