#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)

vector <int> dy = {0, 1, 0, -1};
vector <int> dx = {1, 0, -1, 0};

const int INF = 1000000000;
const ll INFLL = 100000000000000000;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x *= x;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main(){
	int t; cin >> t;
	ll n; cin >> n;
	int now = 0;
	vector <int> now2next(105, -1);
	vector <ll> dist;
	ll ans = 0;
	ll b = 0;
	ll pre_b = 0;
	ll all = 0;
	ll cnt = 0;
	while(n > 0){
		int tmp = (100 - now + t - 1) / t;
		int next = (t * tmp + now) - 100;
		if(now2next.at(now) != -1){
			break;
		}
		now2next.at(now) = next;
		now = next;
		b = tmp;
		n --;
		all += b;
		dist.push_back(b);
		pre_b = b;
		cnt ++;
		//cout << b << endl;
	}

	//cout << n << endl;
	ans = all;
	ans += all * (n / cnt);
	//cout << ans << endl;
	n %= cnt;
	for(auto d: dist){
		if(n == 0) break;
		n--;
		//cout << "jfalk" << d << endl;
		ans += d;
	}

	//cout << ans << endl;

	cout << ((100 + t) * ans / 100) - 1 << endl; 


}
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N, M;
  cin >> N >> M;
  vector<i64> H(N);
  rep(i,0,N) {
    cin >> H[i];
  }
  sort(all(H));
  vector<i64> W(M);
  rep(i,0,M) {
    cin >> W[i];
  }
  sort(all(W));

  vector<i64> left(N + 1);
  for(int i = 2; i < N; i += 2) {
    left[i - 1] = left[i - 2];
    left[i] = left[i - 2] + H[i - 1] - H[i - 2];
  }
  left[N] = left[N - 1];
  vector<i64> right(N + 1);
  for(int i = N - 2; i >= 0; i -= 2) {
    right[i + 1] = right[i + 2];
    right[i] = right[i + 2] + H[i + 1] - H[i];
  }
  right[0] = right[1];

  i64 res = 1e18;
  rep(i,0,N) {
    i64 h = H[i];
    i64 ans = left[i] + right[i + 1];
    if(i % 2 == 1) {
      ans += H[i + 1] - H[i - 1];
    }
    i64 MIN = 1e18;
    auto iter = lower_bound(all(W), h);
    if(iter != W.end()) {
      MIN = std::min(MIN, abs(h - *iter));
    }
    if(iter != W.begin()) {
      MIN = std::min(MIN, abs(h - *(--iter)));
    }
    res = std::min(res, ans + MIN);
  }
  cout << res << endl;
}
