#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
	ll l,r,ans=2e9;
	cin >> l >> r;
	if (r-l+1 <= 2019) {
		for (ll i=l; i<r; i++) {
			for (ll j=i+1; j<=r; j++) {
				ans = min(ans, ((i%2019)*(j%2019))%2019);
			}
		}
		cout << ans << '\n';
	} else {
		cout << 0 << '\n';
	}
	return 0;
}

#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, K; cin >> N >> K;
  int x[N]; rep(i,N) cin >> x[i];
  int ans = 1000000000;
  rep(i,N-K+1){
    int MAX = x[i+K-1], MIN = x[i];
    int tmp;
    if (MIN > 0 || MAX<0 ){
      tmp = max(abs(MIN), abs(MAX));
    } 
    else {
      tmp = MAX - MIN + min(MAX, abs(MIN));
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}
