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