#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int h[2005];
int main() {
  int i, n, a, b, ans = 0;
  scanf("%d %d %d", &n, &a, &b);
  for (i = 0; i < n; ++i) scanf("%d", &h[i]);
  sort(h, h + n, cmp);
  if (h[a - 1] > h[a]) ans = h[a - 1] - h[a];
  printf("%d\n", ans);
  return 0;
}
