#include <bits/stdc++.h>
using namespace std;
long long o, t, k, n, a, b, mx = INT_MIN;
vector<long long> q;
int main() {
  cin >> n >> a >> b;
  long long c[n];
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    q.push_back(c[i]);
  }
  sort(q.begin(), q.end());
  cout << q[q.size() - 1 - (a - 1)] - q[b - 1];
}
