#include <bits/stdc++.h>
using namespace std;
const char* inputCLineOrWord(int mode) {
  static char buf[65536];
  static int bufLen = sizeof(buf);
  static int bufPos = sizeof(buf);
  static bool canReadFlag = true;
  static bool crFlag = false;
  static bool enterFlag = false;
  if (canReadFlag &&
      (enterFlag ? bufLen <= bufPos : (int)sizeof(buf) <= bufPos + bufPos)) {
    if (0 < bufLen - bufPos) {
      memmove(buf, buf + bufPos, bufLen - bufPos);
      bufLen -= bufPos;
    } else {
      bufLen = 0;
    }
    char* result = fgets(buf + bufLen, sizeof(buf) - bufLen, stdin);
    canReadFlag = (result != NULL);
    if (result != NULL) {
      int n = strlen(result);
      enterFlag = (n != (int)sizeof(buf) - 1 - bufLen ||
                   (1 <= bufLen + n && buf[bufLen + n - 1] == '\n'));
      bufLen += n;
    }
    bufPos = 0;
  }
  if (mode == 0) {
    int pos = bufPos;
    while (true) {
      char c = buf[pos];
      if (c == 32) {
        buf[pos++] = '\0';
        break;
      } else if (c == 10) {
        if (crFlag) {
          crFlag = false;
          if (bufPos == pos) {
            pos = ++bufPos;
            continue;
          }
        }
        buf[pos++] = '\0';
        break;
      } else if (c == 13) {
        crFlag = true;
        buf[pos++] = '\0';
        break;
      } else if (c == 0) {
        break;
      }
      ++pos;
    }
    const char* ret = buf + bufPos;
    bufPos = pos;
    while (true) {
      char c = buf[bufPos];
      if (c == 32 || c == 10 || c == 13) {
        ++bufPos;
      } else {
        break;
      }
    }
    return ret;
  } else if (mode == 1) {
    int pos = bufPos;
    while (true) {
      char c = buf[pos];
      if (c == 10) {
        if (crFlag) {
          crFlag = false;
          if (bufPos == pos) {
            pos = ++bufPos;
            continue;
          }
        }
        buf[pos++] = '\0';
        break;
      } else if (c == 13) {
        crFlag = true;
        buf[pos++] = '\0';
        break;
      } else if (c == 0) {
        break;
      }
      ++pos;
    }
    const char* ret = buf + bufPos;
    bufPos = pos;
    if (crFlag) {
      while (true) {
        char c = buf[bufPos];
        if (c == 13) {
          ++bufPos;
          crFlag = false;
          break;
        } else {
          break;
        }
      }
    }
    return ret;
  } else if (mode == 2) {
    return bufLen <= bufPos ? NULL : buf + bufPos;
  }
  assert(false);
  return NULL;
}
const char* inputCWord() { return inputCLineOrWord(0); }
int inputInt() { return atoi(inputCWord()); }
void print_unit(bool val) { printf("%s", val ? "true" : "false"); }
void print_unit(int val) { printf("%d", val); }
void print_unit(unsigned int val) { printf("%u", val); }
void print_unit(size_t val) { printf("%zd", val); }
void print_unit(const void* val) { printf("%p", val); }
void print_unit(long long val) { printf("%lld", val); }
void print_unit(double val) { printf("%g", val); }
void print_unit(const char* val) { printf("%s", val); }
void print_unit(const std::string& val) { printf("%s", val.c_str()); }
template <class T>
void print_unit(const std::vector<T>& val) {
  printf("vec(%d) {", (int)val.size());
  for (int i = 0; i < (int)val.size(); ++i) {
    fputc(' ', stdout);
    print_unit(val[i]);
  }
  printf(" }");
}
int N;
vector<int> T;
vector<int> U;
vector<int> V;
vector<vector<int> > E;
int a;
int b;
int turn;
int cnt;
int main() {
  N = inputInt();
  T.resize(max((int)T.size(), (int)N));
  for (int $1 = 0; $1 < N; ++$1) T[$1] = 0;
  U = vector<int>();
  V = vector<int>();
  U.emplace_back(inputInt() - 1);
  V.emplace_back(inputInt() - 1);
  E.resize(max((int)E.size(), (int)N));
  for (int $1 = 0; $1 < N; ++$1) E[$1] = vector<int>();
  for (int $1 = 0; $1 < N - 1; ++$1)
    if (true || ($1)) {
      {
        a = inputInt() - 1;
        b = inputInt() - 1;
      }
      E[a].emplace_back(b);
      E[b].emplace_back(a);
    }
  turn = 0;
  cnt = 0;
  while (true) {
    assert(!(U.empty() && V.empty()));
    for (const auto& u : move(U)) {
      T[u] |= 1;
      if (!(T[u] & 2)) {
        ++cnt;
      }
      for (int $1 = 0; $1 < (int)E[u].size(); ++$1) {
        const auto& e = E[u][$1];
        if (!(T[e] & 1)) {
          U.emplace_back(e);
        }
      }
    }
    for (const auto& v : move(V)) {
      T[v] |= 2;
      if (T[v] & 1) {
        --cnt;
      }
      for (int $1 = 0; $1 < (int)E[v].size(); ++$1) {
        const auto& e = E[v][$1];
        if (!(T[e] & 2)) {
          V.emplace_back(e);
        }
      }
    }
    if (cnt == 0) {
      break;
    }
    ++turn;
  }
  print_unit(turn - 1), fputc('\n', stdout);
  return 0;
}
