#include <bits/stdc++.h>
double min(double a, double b) { return a < b ? a : b; }
int xx[100000];
int compare(const void *a, const void *b) {
  int i = *(int *)a;
  int j = *(int *)b;
  return xx[i] - xx[j];
}
int main() {
  static int ii[100000];
  int n, k, i, i_, xn, yn;
  double ans;
  scanf("%d%d", &n, &k), k--;
  for (i = 0; i < n; i++) {
    scanf("%d", &xx[i]);
    ii[i] = i;
  }
  qsort(ii, n, sizeof *ii, compare);
  scanf("%d%d", &xn, &yn);
  if (k == n) {
    printf("%f\n",
           min(hypot(xn - xx[ii[0]], yn), hypot(xn - xx[ii[n - 1]], yn)) +
               xx[ii[n - 1]] - xx[ii[0]]);
    return 0;
  }
  ans = hypot(xn - xx[k], yn) +
        min(hypot(xn - xx[ii[0]], yn), hypot(xn - xx[ii[n - 1]], yn)) +
        xx[ii[n - 1]] - xx[ii[0]];
  i_ = -1;
  for (i = 0; i < n; i++)
    if (ii[i] == k) {
      i_ = i;
      break;
    }
  for (i = i_; i < n; i++) {
    double d;
    d = min(
        xx[ii[i]] - xx[k] + xx[ii[i]] - xx[ii[0]] + hypot(xn - xx[ii[0]], yn),
        xx[k] - xx[ii[0]] + xx[ii[i]] - xx[ii[0]] + hypot(xn - xx[ii[i]], yn));
    if (i + 1 < n)
      d += min(hypot(xn - xx[ii[i + 1]], yn), hypot(xn - xx[ii[n - 1]], yn)) +
           xx[ii[n - 1]] - xx[ii[i + 1]];
    ans = min(ans, d);
  }
  for (i = i_; i >= 0; i--) {
    double d;
    d = min(xx[k] - xx[ii[i]] + xx[ii[n - 1]] - xx[ii[i]] +
                hypot(xn - xx[ii[n - 1]], yn),
            xx[ii[n - 1]] - xx[k] + xx[ii[n - 1]] - xx[ii[i]] +
                hypot(xn - xx[ii[i]], yn));
    if (i > 0)
      d += min(hypot(xn - xx[ii[i - 1]], yn), hypot(xn - xx[ii[0]], yn)) +
           xx[ii[i - 1]] - xx[ii[0]];
    ans = min(ans, d);
  }
  printf("%f\n", ans);
  return 0;
}
