#include "bits/stdc++.h"
#define int          long long int
#define mp           make_pair
#define pb           emplace_back
#define F            first
#define S            second
using vi       =     std::vector<int>;
using vvi      =     std::vector<vi>;
using pii      =     std::pair<int, int>;
using vpii     =     std::vector<pii>;
using vvpii    =     std::vector<vpii>;
using namespace std;
const int inf  =     1e18 + 10;
const int N    =     2e6 + 10;
int n, taka;
long double a[N], l, r, ans = inf, m1, m2;
long double f(long double x) {
	long double cost = 0;
	for (int i = 1; i <= n; i++) {
		cost += max(x, a[i] - x);
	}
	ans = min(ans, cost);
	return cost;
}
void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	r = inf;
	while (l / (long double) n <= r / (long double) n - 1e-6) {
		m1 = (r - l) / 3.0 + l;
		m2 = r - (r - l) / 3.0;
		if (f(m1) < f(m2))
			r = m2;
		else
			l = m1;
	}
	cout << fixed << setprecision(6) << ans / (long double) n;
}
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	solve(); return 0;
	return 0;
}
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

class TaskC {
 public:
  void solveOne(istream &in, ostream &out) {
    int n;
    int l;
    in >> n;
    in >> l;
    vector<int> a(n + 2);
    vector<int> b(n + 2);
    for (int i = 1; i <= n; ++i) {
      in >> a[i];
      a[i] -= i;
    }
    for (int i = 1; i <= n; ++i) {
      in >> b[i];
      b[i] -= i;
    }
    a[n + 1] = b[n + 1] = l + 1 - (n + 1);
    n += 2;

    int ai = 0;
    int64 res = 0;

    for (int i = 0; i < n;) {
      int j = i;
      int val = b[i];
      while (j < n && b[j] == val) ++j;
      while (ai < n && a[ai] < val) ++ai;
      if (ai >= n || a[ai] != val) {
        out << -1 << "\n";
        return;
      }
      int aj = ai;
      while (aj < n && a[aj] == val) ++aj;
      res += max(0, ai - i);
      res += max(0, j - aj);
      i = j;
    }
    out << res << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskC solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
