#include <bits/stdc++.h>
using namespace std;
double a[100010];
double xx, yy, t;
int n, m, i, j;
double len(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%lf", &a[i]);
  t = a[m];
  sort(a + 1, a + 1 + n);
  a[0] = a[1];
  a[n + 1] = a[n];
  scanf("%lf%lf", &yy, &xx);
  if (n == 1) {
    printf("%.10lf\n", len(xx, yy, 0, a[1]));
    return 0;
  }
  if (m == n + 1) {
    printf("%.10lf\n", min(len(xx, yy, 0, a[1]), len(xx, yy, 0, a[n])) +
                           len(0, a[1], 0, a[n]));
  } else {
    m = lower_bound(a + 1, a + 1 + n, t) - a;
    if (n == 2) {
      printf("%.10lf\n",
             min(len(xx, yy, 0, a[m]) + len(xx, yy, 0, a[3 - m]),
                 len(0, a[3 - m], 0, a[m]) + len(xx, yy, 0, a[3 - m])));
      return 0;
    }
    double ans = 1e10;
    for (i = 1; i <= n; i++) {
      ans = min(
          ans, len(0, t, 0, a[1]) + len(0, a[1], 0, a[i]) +
                   len(0, max(a[i + 1], t), 0, a[n]) + len(0, a[i], xx, yy) +
                   min(len(xx, yy, 0, max(a[i + 1], t)), len(xx, yy, 0, a[n])));
      ans = min(
          ans, len(0, t, 0, a[n]) + len(0, a[n], 0, a[i]) +
                   len(0, min(a[i - 1], t), 0, a[1]) + len(0, a[i], xx, yy) +
                   min(len(xx, yy, 0, min(a[i - 1], t)), len(xx, yy, 0, a[1])));
    }
    ans = min(ans, len(0, t, 0, a[1]) + len(0, a[1], xx, yy) +
                       min(len(xx, yy, 0, a[m + 1]), len(xx, yy, 0, a[n])) +
                       len(0, a[m + 1], 0, a[n]));
    ans = min(ans, len(0, t, 0, a[n]) + len(0, a[n], xx, yy) +
                       min(len(xx, yy, 0, a[m - 1]), len(xx, yy, 0, a[1])) +
                       len(0, a[m - 1], 0, a[1]));
    for (i = m + 1; i <= n; i++) {
      ans = min(ans, len(0, t, 0, a[i]) + len(0, a[1], 0, a[i]) +
                         len(0, a[i + 1], 0, a[n]) + len(0, a[1], xx, yy) +
                         min(len(xx, yy, 0, a[i + 1]), len(xx, yy, 0, a[n])));
    }
    for (i = 1; i <= m; i++) {
      ans = min(ans, len(0, t, 0, a[i]) + len(0, a[n], 0, a[i]) +
                         len(0, a[i - 1], 0, a[1]) + len(0, a[n], xx, yy) +
                         min(len(xx, yy, 0, a[i - 1]), len(xx, yy, 0, a[1])));
    }
    ans = min(
        ans, len(0, t, 0, a[1]) + len(0, a[n], xx, yy) + len(0, a[1], 0, a[n]));
    ans = min(
        ans, len(0, t, 0, a[n]) + len(0, a[1], xx, yy) + len(0, a[1], 0, a[n]));
    printf("%.10lf\n", ans);
  }
  return 0;
}
