#include <bits/stdc++.h>
using namespace std;
int main() {
  long long b, d, s;
  cin >> b >> d >> s;
  unsigned long long min_ans = 4e18;
  for (int start = 0; start < 3; ++start) {
    for (int finish = 0; finish < 3; ++finish) {
      unsigned long long min_days_b = b;
      if (start > 0) {
        min_days_b += 1;
      }
      unsigned long long min_days_d = d;
      if (start == 2) {
        min_days_d += 1;
      }
      if (finish == 0) {
        min_days_d += 1;
      }
      unsigned long long min_days_s = s;
      if (finish < 2) {
        min_days_s += 1;
      }
      unsigned long long min_days = max(min_days_s, min_days_d);
      min_days = max(min_days, min_days_b);
      unsigned long long ans = 0;
      ans += min_days - b;
      if (start > 0) {
        --ans;
      }
      ans += min_days - d;
      if (start == 2) {
        --ans;
      }
      if (finish == 0) {
        --ans;
      }
      ans += min_days - s;
      if (finish < 2) {
        --ans;
      }
      if (ans < min_ans) {
        min_ans = ans;
      }
    }
  }
  cout << min_ans << endl;
  return 0;
}
