#include <bits/stdc++.h>
using namespace std;
long long int sx, sy, x[100005], n, k;
void outside() {
  sort(x, x + n);
  printf("%0.20lf\n", min(hypot(x[0] - sx, sy), hypot(x[n - 1] - sx, sy)) +
                          (x[n - 1] - x[0]));
  exit(0);
}
double cal(long long int left, long long int right) {
  if (left == right) return 0;
  double len = x[right - 1] - x[left];
  double res0 = hypot(x[left] - sx, sy);
  double res1 = hypot(x[right - 1] - sx, sy);
  if (x[left] <= k && k <= x[right - 1]) {
    res0 += x[right - 1] - k;
    res1 += k - x[left];
  }
  return min(res0, res1) + len;
}
int main() {
  cin >> n >> k;
  k--;
  for (long long int i = 0; i < ((long long int)(n)); i++) cin >> x[i];
  cin >> sx >> sy;
  if (n == k) outside();
  k = x[k];
  sort(x, x + n);
  double res = (1ll << (long long int)(60));
  for (long long int i = 0; i < ((long long int)(n + 1)); i++)
    res = min(res, cal(0, i) + cal(i, n));
  printf("%0.20lf\n", res);
}
