#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, k, h, x, a[N];
double ans, tmp;
double dis(int x) {
  return sqrt(1.0 * (x - a[n + 1]) * (x - a[n + 1]) + 1.0 * h * h);
}
int main() {
  cin >> n >> k, ans = 1e12;
  for (int i = 1; i <= n + 1; ++i) scanf("%d", &a[i]);
  scanf("%d", &h), x = a[k];
  sort(a + 1, a + n + 1);
  if (k == n + 1) {
    ans = min(dis(a[1]), dis(a[n])) + a[n] - a[1];
    printf("%.8lf\n", ans);
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    if (a[i] == x) k = i;
  if (k > 1)
    ans = min(ans, a[n] - a[k] + dis(a[n]) + min(dis(a[1]), dis(a[k - 1])) +
                       a[k - 1] - a[1]);
  if (k < n)
    ans = min(ans, a[k] - a[1] + dis(a[1]) + min(dis(a[n]), dis(a[k + 1])) +
                       a[n] - a[k + 1]);
  for (int i = 1; i <= n; ++i) {
    if (i <= k) {
      tmp = i > 1 ? min(dis(a[1]), dis(a[i - 1])) + a[i - 1] - a[1] : 0;
      ans = min(ans, a[n] - a[k] + a[n] - a[i] + dis(a[i]) + tmp);
      ans = min(ans, a[k] - a[i] + a[n] - a[i] + dis(a[n]) + tmp);
    } else {
      tmp = i < n ? min(dis(a[i + 1]), dis(a[n])) + a[n] - a[i + 1] : 0;
      ans = min(ans, a[k] - a[1] + a[i] - a[1] + dis(a[i]) + tmp);
      ans = min(ans, a[i] - a[k] + a[i] - a[1] + dis(a[1]) + tmp);
    }
  }
  printf("%.8lf\n", ans);
  return 0;
}
