#include <bits/stdc++.h>
using namespace std;
int n, k;
double newtag;
double a[100100];
double ans;
double y;
double d(int l) { return sqrt((a[l] - a[n + 1]) * (a[l] - a[n + 1]) + y * y); }
double cal1(int l, int r) { return a[r] - a[l] + min(d(l), d(r)); }
double cal2(int l, int r) {
  return a[r] - a[l] +
         min(d(l) + fabs(newtag - a[r]), d(r) + fabs(newtag - a[l]));
}
int main() {
  cin >> n >> k;
  cout << setprecision(10) << fixed;
  for (int i = 1; i <= n + 1; i++) {
    int x;
    scanf("%lf", &a[i]);
  }
  scanf("%lf", &y);
  newtag = a[k];
  sort(a + 1, a + n + 1);
  if (k == n + 1) {
    double ans = cal1(1, n);
    cout << ans;
  } else {
    double ans = cal2(1, n);
    for (int i = 1; i < n; i++) {
      ans = min(ans,
                min(cal1(1, i) + cal2(i + 1, n), cal2(1, i) + cal1(i + 1, n)));
    }
    cout << ans;
  }
}
