#include <iostream>
#include <algorithm>
#include <string>
#include <complex>
#include <vector>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

#include <chrono>
#include <random>
#include <cassert>

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(a) { cerr << #a << " = " << a << endl;}
#define debugV(vec) { cerr << #vec << " : "; for(auto v : vec) cerr << v << " "; cerr << endl; }
#define debug2D(vec2D, w) { cerr << #vec2D << endl;  for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } } 
#define debugVP(vec) { cerr << #vec << " : ";  for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;}
#define debug2DP(vec2D) { cerr << #vec2D << endl;  for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } }

typedef long long ll;

constexpr ll INF = 1001001001; //32 ~2*10^10 //64 ~9*10^19
//constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;
const double EPS = round(1e-6);
const char en = '\n';

/*
struct Edge {
	Edge(int _s, int _t, ll _cost = 1) : from(_s), to(_t), cost(_cost) {};
	int from, to;
	ll cost;
	//ll fee;
};
*/
typedef ll Edge;
/*
struct Edge {
	int id;
	int from, to;

	Edge() { id = from = to = -1; };
	Edge(int a, int b, int c) : id(a), from(b), to(c) {};
};
*/
typedef vector<vector<Edge>> Graph;
/*
void add_edge(Graph& g, int from, int to, ll cost = 1) {
	g[from].push_back(Edge(from, to, cost));
}
*/
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

void solve() {
  ll b, c; cin >> b >> c;
	ll l1 = (b - c / 2), l2 = (-b - (c - 1) / 2), r1 = (b + (c - 2) / 2), r2 = (-b + (c - 1) / 2);
	if (c == 1) {
	  if (b == 0) cout << 1 << endl;
		else cout << 2 << endl;
	}
	else if (c == 2) {
		if (b == 0) cout << 2 << endl;
		else cout << 3 << endl;
	}
	else if (b == 0) {
	  cout << r1 - l1 + 1 << endl; 
	}
	else if (b < 0) {
		if (r1 >= l2) {
			cout << r2 - l1 + 1 << endl;
 		}
		else {
		  cout << r1 - l1 + r2 - l2 + 2 << endl;
		}
	}
	else {
		if (r2 >= l1) {
			cout << r1 - l2 + 1 << endl;
		}
		else {
			cout << r1 - l1 + r2 - l2 + 2 << endl;
		}
	}


}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	//rep(i,3)
	solve();

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

const int maxn = 2005;
const long long inf = 1e18+10;
int n, m;
vector<pair<long long,int> > g[maxn];
void dijkstra(int v) {
    long long d[n+1];
    for(int i=0; i<=n; i++) d[i] = inf;

    long long ans = inf;
    d[v] = 0;
    priority_queue<pair<long long,int> > pq;
    pq.push({0, v});
    bool p[n+1];
    memset(p, 0, sizeof p);
    while(!pq.empty()) {
        int cur = pq.top().second;
        pq.pop();
        if(p[cur]) continue;
        p[cur] = 1;
        for(int u=0; u<g[cur].size(); ++u) {
            long long b = g[cur][u].first, w = g[cur][u].second;
            //cout << b << " " << w << endl;
            if(b==v) {
                ans = min(ans, d[cur]+w);

            }
            else if(d[cur]+w<d[b]) {

                d[b] = d[cur]+w;
                pq.push({-d[b], b});
            }
        }
    }
    if(ans==inf) ans = -1;
    cout << ans << " ";
}
void Run_Case() {
    cin >> n >> m;
    for(int i=1; i<=m; i++) {
        int u, v, w; cin >> u >> v >> w;
        g[u].push_back({v, w});
    }
    for(int i=1; i<=n; i++) {
        dijkstra(i);
    }
}
int main() {
    Run_Case();
    return 0;
}
