#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, x, cnt, ans;
deque<long long> V;
map<long long, long long> mp;
long long arr[1000001];
int main() {
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  sort(arr + 1, arr + n + 1);
  ans = (n - a) + 1;
  x = arr[ans] - arr[b];
  cout << x << endl;
}
