#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
void pre() {
  cout.setf(ios::fixed);
  cout.precision(20);
  cerr.setf(ios::fixed);
  cerr.precision(3);
}
void post() {
  fprintf(stderr, "\n");
  fprintf(stderr, "Execution time: %Lf", (long double)clock());
}
const int MAXN = 100100;
int h[99999];
inline void solve(int test_number) {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  swap(a, b);
  sort(h, h + n);
  if (h[n - b] - h[a - 1] <= 0) {
    puts("0");
    return;
  }
  printf("%d", h[n - b] - h[a - 1]);
  return;
}
int main() {
  pre();
  int n = 1;
  for (int i = 0; i < n; i++) {
    solve(i + 1);
  }
  post();
  return 0;
}
