#include <bits/stdc++.h>
using namespace std;
int n, k, i, a[100010];
double d1, d2, xc, yc, x, y;
double dist(int a, int b, int c, int d) {
  return sqrt(1ll * (a - c) * (a - c) + 1ll * (b - d) * (b - d));
}
double d;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n + 1; i++) scanf("%d", &a[i]);
  cin >> yc;
  x = a[k];
  xc = a[n + 1];
  sort(a + 1, a + n + 1);
  if (n == 1) {
    d = dist(xc, yc, a[1], 0);
    printf("%.8lf", d);
    return 0;
  }
  if (k == n + 1) {
    d = min(dist(xc, yc, a[1], 0), dist(xc, yc, a[n], 0));
    d += a[n] - a[1];
    printf("%.8lf", d);
    return 0;
  }
  int dx, dy, dxx = 1, dyy = n;
  for (i = 1; i <= n; i++) {
    if (a[i] < x) {
      dxx = i;
    }
    if (a[i] > x) {
      dyy = i;
      break;
    }
  }
  d1 = 100000000 + .0;
  d1 = min(d1, a[n] - a[1] + a[n] - x + dist(xc, yc, a[1], 0));
  d1 = min(d1, a[n] - a[1] + x - a[1] + dist(xc, yc, a[n], 0));
  for (i = 1; i <= dxx + 1; i++) {
    if (a[i] > x) break;
    double r = dist(xc, yc, a[1], 0);
    if (i > 1)
      r = a[i - 1] - a[1] +
          min(dist(xc, yc, a[1], 0), dist(xc, yc, a[i - 1], 0));
    d1 = min(d1, a[n] - x + a[n] - a[i] + dist(xc, yc, a[i], 0) + r);
    d1 = min(d1, x - a[i] + a[n] - a[i] + dist(xc, yc, a[n], 0) + r);
  }
  if (dxx == 1 && x == a[dxx]) dxx = 0;
  for (i = dxx + 1; i <= n; i++) {
    double t = dist(xc, yc, a[n], 0);
    if (i < n)
      t = a[n] - a[i + 1] +
          min(dist(xc, yc, a[n], 0), dist(xc, yc, a[i + 1], 0));
    d1 = min(d1, a[i] - x + a[i] - a[1] + dist(xc, yc, a[1], 0) + t);
    d1 = min(d1, x - a[1] + a[i] - a[1] + dist(xc, yc, a[i], 0) + t);
  }
  printf("%.10lf", d1);
  return 0;
}
