#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, maxn = 2e5 + 1;
  int h[maxn];
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++) cin >> h[i];
  sort(h + 1, h + 1 + n);
  if (h[n - a + 1] - h[b] > 0)
    cout << h[n - a + 1] - h[b];
  else
    cout << 0;
  return 0;
}
