#include <bits/stdc++.h>
using namespace std;
int64_t res = 3 * 1e18, a[10];
int main() {
  cin >> a[1] >> a[2] >> a[3];
  int64_t tmp = min(min(a[1], a[2]), a[3]);
  for (int i = 1; i <= 3; i++) {
    a[i] -= tmp;
    a[i + 3] = a[i];
  }
  for (int i = 1; i <= 3; i++) {
    int64_t sum, maxn = max(max(a[i], a[i + 1]), a[i + 2]);
    if (a[i] == maxn) {
      sum = 2 * a[i] - a[i + 1] - a[i + 2] - 2;
      if (a[i + 2] == maxn)
        sum += 2;
      else if (a[i + 1] == maxn)
        sum++;
      res = min(res, sum);
    }
  }
  cout << res;
}
