#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int a[4];
  cin >> a[1] >> a[2] >> a[3];
  sort(a + 1, a + 4);
  reverse(a + 1, a + 4);
  for (long long int i = 1; i <= 3; i++) a[i] -= a[3];
  if (a[1] == a[2])
    cout << max(0LL, a[2] - 1);
  else {
    if (a[2] == 1)
      cout << a[1] - 1 + max(0LL, a[1] - 2);
    else if (a[2] == 0)
      cout << 2 * (a[1] - 1);
    else {
      long long int x = a[2] - 1;
      a[1] = a[1] - a[2] + 1;
      cout << a[1] - 1 + max(0LL, a[1] - 2) + x;
    }
  }
}
