#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, temp;
  int h[2005];
  while (cin >> n >> a >> b) {
    for (int i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (int i = 0; i < n - 1; i++)
      for (int j = 0; j < n - i - 1; j++) {
        if (h[j] < h[j + 1]) {
          temp = h[j];
          h[j] = h[j + 1];
          h[j + 1] = temp;
        }
      }
    if (h[a - 1] > h[a])
      cout << h[a - 1] - h[a] << endl;
    else
      cout << "0" << endl;
  }
  return 0;
}
