#include <bits/stdc++.h>
using namespace std;
long long getAns(const vector<long long>& food, const vector<long long>& var) {
  long long ans = 0;
  for (int i = 0; i < 3; i++) {
    if (var[i] < food[i]) {
      return -1;
    }
    ans += var[i] - food[i];
  }
  return ans;
}
int main() {
  cin.sync_with_stdio(0);
  vector<long long> food(3);
  for (int i = 0; i < 3; i++) {
    cin >> food[i];
  }
  long long ans = -1;
  vector<long long> var(3, 0);
  for (int start = 0; start < 4; start++)
    for (int end = start + 1; end < 4; end++) {
      for (int i = 0; i < 3; i++) {
        if (i >= start && i < end) {
          var[i] = 1;
        } else {
          var[i] = 0;
        }
      }
      long long locAns = getAns(food, var);
      if (locAns >= 0 && (ans == -1 || ans > locAns)) {
        ans = locAns;
      }
    }
  long long maxDays = max(food[0], max(food[1], food[2]));
  long long minDays = max(0LL, maxDays - 2);
  for (long long fullDays = minDays; fullDays <= maxDays; fullDays++) {
    for (int start = 0; start < 4; start++)
      for (int end = 0; end < 4; end++) {
        for (int i = 0; i < 3; i++) {
          var[i] = fullDays;
          if (i >= start) {
            var[i] += 1;
          }
          if (i < end) {
            var[i] += 1;
          }
        }
        long long locAns = getAns(food, var);
        if (locAns >= 0 && (ans == -1 || ans > locAns)) {
          ans = locAns;
        }
      }
  }
  cout << ans << endl;
  return 0;
}
