#include <bits/stdc++.h>
using namespace std;
long long Min(long long a, long long b) { return a < b ? a : b; }
bool cmp(long long a, long long b) { return a > b; }
long long a[3];
int main() {
  while (~scanf("%lld%lld%lld", &a[0], &a[1], &a[2])) {
    long long ans = 0;
    sort(a, a + 3, cmp);
    a[0] -= a[2], a[1] -= a[2], a[2] = 0;
    if (a[0] == 0 && a[1] == 0)
      ans = 0;
    else if (a[1] == 0)
      ans += (a[0] - 1) * 2;
    else if (a[0] == a[1])
      ans += a[1] - 1;
    else {
      ans += a[1];
      a[0] -= a[1], a[1] = 0;
      ans += (a[0] - 1) * 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
