#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n,m;cin >> n >> m;
    vector<deque<ll>> g(n);
    rep(i,n){
        rep(j,m){
            ll a;cin >> a;
            g[i].pb(a);
        }
    }
    ll ans=inf;
    set<ll> st;
    rep(i,m){
        rep(j,n){
            while(st.count(g[j].front())){
                g[j].pop_front();
            }
        }
        map<ll,ll> mp;
        rep(j,n){
            mp[g[j].front()]++;
        }
        ll del=-1,pp=-1;
        for(auto p:mp){
            if(chmax(pp,p.se))del=p.fi;
        }
        chmin(ans,pp);st.ins(del);
    }
    cout << ans <<endl;
}

#define C
typedef long long readtype;

/* Header {{{ */
#ifdef C
#include <stdio.h>
#include <math.h>
#include <string.h>
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
template<typename type> type abs(type a) { return a < 0 ? -a : a; }
template<typename type> type min(type a, type b) { return a < b ? a : b; }
template<typename type> type beMin(type &a, type b) { return a = (a < b ? a : b); }
template<typename type> type max(type a, type b) { return a > b ? a : b; }
template<typename type> type beMax(type &a, type b) { return a = (a > b ? a : b); }
template<typename type> void swap(type &a, type &b) { type c; c = a; a = b; b = c; }
#endif

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

typedef long long var;

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}
/* }}} */

const int N = 311;

int n, m;
int a[N][N], have[N], pos[N];
bool ban[N];

bool check(int t);

int main() {
  /*
#ifndef ONLINE_JUDGE
  freopen("source.in", "r", stdin);
  freopen("source.out", "w", stdout);
#endif
*/
  n = read(), m = read();
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) a[i][j] = read();
  }
  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (!check(mid)) l = mid + 1;
    else r = mid;
  }
  printf("%d\n", l);
  return 0;
}

bool check(int t) {
  memset(ban, false, sizeof(ban));
  memset(have, 0, sizeof(have));
  memset(pos, 0, sizeof(pos));
  for (int i = 1; i <= n; ++i) have[a[i][++pos[i]]]++;
  while (true) {
    bool ok = true;
    for (int i = 1; i <= m; ++i) {
      if (have[i] <= t) continue;
      ok = false;
      ban[i] = true;
    }
    if (ok) break;
    for (int i = 1; i <= n; ++i) {
      while (pos[i] <= m && ban[a[i][pos[i]]]) {
        have[a[i][pos[i]]]--;
        have[a[i][++pos[i]]]++;
      }
      if (pos[i] > m) return false;
    }
  }
  return true;
}


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

int n ;
LL ar[200005] ;

pair<LL,LL> BS(const int lower, const int upper){
	LL extra ;
	if(lower == 0)	extra =  0 ;
	else 	extra = ar[lower - 1] ;

	int l = lower, u = upper, mid, indx = -1 ;
	LL min_diff = LLONG_MAX ;

	while(l <= u){
		mid = (l + u) / 2 ;
		LL left = ar[mid] - extra ;
		LL right = ar[upper] - ar[mid] ;

		if(abs(left - right) < min_diff){
			min_diff = abs(left - right) ;
			indx = mid ;
		}

		if(left == right)
			break ;
		else if(left > right)
			u = mid - 1 ;
		else
			l = mid + 1 ;
	}

	return {ar[indx] - extra, ar[upper] - ar[indx]} ;
}

int main(){

	cin >> n >> ar[0] ;
	for(int i = 1 ; i < n ; i++){
		cin >> ar[i] ;
		ar[i] += ar[i-1] ;
	}

	LL ans = LLONG_MAX ;
	for(int i = 1 ; i + 2 < n ; i++){
		pair<LL,LL> p1 = BS(0, i) ;
		pair<LL,LL> p2 = BS(i + 1, n - 1) ;
		ans = min(ans, ( max(p1.first, max(p1.second, max(p2.first, p2.second)))
					- min(p1.first, min(p1.second, min(p2.first, p2.second))) )) ;
	}
	cout << ans << endl ;

	return 0;
}

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

vector<int> calc_cut_left(vector<long long> pref, int n) {
  vector<int> ans(n);
  int cur = 0;
  ans[1] = 0;
  for (int i = 2; i + 2 < n; i++) {
    long long s1 = abs(pref[cur + 1] - (pref[i] - pref[cur + 1]));
    long long s2 = abs(pref[cur] - (pref[i] - pref[cur]));
    while (abs(pref[cur + 1] - (pref[i] - pref[cur + 1])) < abs(pref[cur] - (pref[i] - pref[cur])))
      cur++;
    ans[i] = cur;
  }
  return ans;
}

vector<int> calc_cut_right(vector<long long> pref, int n) {
  vector<int> ans(n);
  int cur = n - 2;
  ans[n - 3] = cur;
  for (int i = n - 4; i >= 1; i--) {
    long long s1 = abs((pref[n - 1] - pref[cur - 1]) - (pref[cur - 1] - pref[i]));
    long long s2 = abs((pref[n - 1] - pref[cur]) - (pref[cur] - pref[i]));
    while (abs((pref[n - 1] - pref[cur - 1]) - (pref[cur - 1] - pref[i])) < abs((pref[n - 1] - pref[cur]) - (pref[cur] - pref[i])))
      cur--;
    ans[i] = cur;
  }
  return ans;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  vector<long long> pref(n, a[0]);
  for (int i = 1; i < n; i++)
    pref[i] = pref[i - 1] + a[i];
  vector<int> pos_left = calc_cut_left(pref, n);
  vector<int> pos_right = calc_cut_right(pref, n);
  long long ans = -1;
  for (int i = 1; i + 2 < n; i++) {
    int l = pos_left[i];
    int r = pos_right[i];
    long long s1 = pref[l];
    long long s2 = pref[i] - pref[l];
    long long s3 = pref[r] - pref[i];
    long long s4 = pref[n - 1] - pref[r];
    long long cur = max({s1, s2, s3, s4}) - min({s1, s2, s3, s4});
    if (ans == -1 || cur < ans)
      ans = cur;
  }
  printf("%lld\n", ans);
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int n,m;
vector<int> fri[501];
int ff[501];
main(){
  while(1){
    scanf("%d",&n);
    scanf("%d",&m);
    if(n==0 && m==0) break;
    memset(ff,0,sizeof(ff));
    for(int i=0;i<=501;i++)
      fri[i].clear();
    for(int i=0;i<m;i++){
      int a,b;
      scanf("%d %d",&a,&b);
      fri[a].push_back(b);
      fri[b].push_back(a);
    }
    int M=fri[1].size();
    for(int i=0;i<M;i++){
      int N=fri[fri[1][i]].size();
      for(int j=0;j<N;j++){
	ff[fri[fri[1][i]][j]]=1;
      }
      ff[fri[1][i]]=1;
    }
    int res=0;
    for(int i=2;i<=n;i++){
      if(ff[i]==1)res++;
      //    printf("%d ",ff[i]);
    }
    printf("%d\n",res);
  }
}


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

int main() {
	int N;
	while ( cin >> N ) {
		if ( N == 0 ) {
			break;
		}
		typedef pair<double, string> P;
		vector<P> ans;
		while ( N-- ) {
			string l;
			int p;
			cin >> l >> p;
			int t = 0;
			int d = 0;
			for ( int i = 0; i < 5; i++ ) {
				int a;
				cin >> a;
				if ( i <= 2 ) t += a;
				else d += a;
			}
			int f, s, m;
			int sum = 0;
			cin >> f >> s >> m;

			t += d*m;
			sum = f*s*m;
			ans.push_back(P(-((double)(sum-p)/(double)t), l));
		}
		sort(ans.begin(), ans.end());

		for ( int i = 0; i < ans.size(); i++ ) {
			cout << ans[i].second << endl;
		}
		cout << '#' << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double,string> P;
const int INF=1e9;
bool comp(P a,P b){
      if(a.first!=b.first)return a.first>b.first;
      int l=min(a.second.size(),b.second.size());
      REP(i,l){
            if(a.second[i]!=b.second[i])return a.second[i]<b.second[i];
      }
      return a.second.size()<b.second.size();
}
int main(){
      int n,p,a,b,c,d,e,f,s,m;
      while(cin>>n&&n){
            vector<P> V;
            string l;
            REP(i,n){
                  cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
                  if(m==1){
                        V.PB(P((double)(s*f-p)/(a+b+c+d+e),l));
                  }else{
                        V.PB(P((double)(s*f*m-p)/(a+b+c+(d+e)*m),l));
                  }
            }
            sort(ALL(V),comp);
            REP(i,V.size()){
                  cout<<V[i].second<<endl;
            }
            cout<<'#'<<endl;
      }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s1[100],s2[100];
string t;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    int i=0,j=0;
    while(j<(ty-sy))
        {cout << 'U'; j++;}
    while(i<(tx-sx))
       { cout << 'R'; i++;}
    i=0;j=0;
    while(j<(ty-sy))
      { cout << 'D'; j++;}
    while(i<(tx-sx))
        {cout << 'L'; i++;}
    i=0;j=0;
    cout << 'L';
    while(j<(ty-sy)+1)
       { cout << 'U'; j++;}
    while(i<(tx-sx)+1)
        {cout << 'R'; i++;}
    cout << 'D';
    cout << 'R';
    i=0;j=0;
    while(j<(ty-sy)+1)
       { cout << 'D'; j++;}
    while(i<(tx-sx)+1)
        {cout << 'L';i++;}
    cout << 'U';

    return 0;
}

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;

  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;

    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }

    res.push_back({i,ex});
  }

  if(n != 1) res.push_back({n,1});

  return res;

}

int main(){
  ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
  ll dx = tx - sx; ll dy = ty - sy;

  cout << string(dx,'R') << string(dy,'U') << string(dx,'L') <<
    string(dy,'D') << 'D' << string(dx+1,'R') <<
    string(dy+1,'U') << 'L' << 'U' << string(dx+1,'L') <<
    string(dy+1,'D') << 'R' << endl;

}


// Etavioxy
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
#define il inline
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch; int f=1;
	while(!isdigit(ch=getchar())) f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(x*10)+(ch^'0');
	return f*x;
}

const int mod = 1e9+7;
enum{N=2023};
il ll qpow(ll a,ll b){
	ll ans= 1;
	for(; b; b>>=1,a=a*a%mod) if( b&1 ){
		ans= ans*a%mod;
	} return ans;
}
il ll inv(ll x){ return qpow(x,mod-2); }
ll fac[N*N],Invf[N*N];
il void init_fac(int n){
	fac[0] = 1;
	rep(i,1,n) fac[i]=fac[i-1]*i%mod;
	Invf[n] = inv(fac[n]);
	rev_rep(i,n,1) Invf[i-1]=Invf[i]*i%mod;
}
il ll comp(ll n,ll m){
	if( n<m ) return 0;
	return fac[n]*Invf[m]%mod*Invf[n-m]%mod;
}

ll f[N][N];
int main(){
	int n = ci(), k = ci();
	if( k==1 ){
		puts("1");
		return 0;
	}
	init_fac(n*k);
	f[0][0] = 1;
	rep(i,1,n){
		f[i][0] = f[i-1][0];
		rep(j,1,i){
			f[i][j] = (f[i-1][j]+f[i][j-1]*(n-j+1)%mod*comp((n-i)+(n-j+1)*(k-1)-1,k-2))%mod;
		}
	}
	printf("%lld\n",(f[n][n]+mod)%mod);
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

//0繰り上がりなし, 1繰り上がりあり
//long long dp[1000][2];
long long dp[1000100][2];
const long long INF = 1LL << 61;

int main(){
    string money = "0";
    string s;
    cin >> s;

    money += s;

    long long n = money.size();
    long long ans = 0;

    //init
    for(int i=0; i< 1000100; ++i){
        for(int j=0; j<2; ++j){
            dp[i][j] = INF;
        }
    }

    //後ろから数える
    int first = money[n-1] - '0';
    dp[n-1][0] = first;
    dp[n-1][1] = 10 - first;

    for(long long  i=n-2; i >= 0; --i){

        int num = money[i] - '0';

            //繰り上がりなし
            dp[i][0] = min(dp[i][0], dp[i+1][0] + num);
            dp[i][0] = min(dp[i][0], dp[i+1][1] + (num+1) );

            //繰り上がりあり
            dp[i][1] = min(dp[i][1], dp[i+1][0] + (10 - num) );
            dp[i][1] = min( dp[i][1], dp[i+1][1] + (10 - (num+1) ) );
    }

    cout << min(dp[0][0], dp[0][1]) << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(z) (z).begin(),(z).end()
#define MOD 1000000007
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll isprime(ll n)
{
	for(int i=2;i<n;i++)
		if(n%i==0)
		return 0;

	return 1;
}
int main()
{
    FAST;
	long double d,t,s;
	cin>>d>>t>>s;
	if(d/s<=t)cout<<"Yes";
	else cout<<"No";

}

#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m, d;
    cin>>n>>m>>d;

    if (1 + d > n) {
        cout<<0<<endl;
    }
    double f = d == 0 ? 1.0 : 2.0;
    printf("%.10f\n", f * (n - d) / n / n * (m - 1));
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

// a^n mod を計算する
long int modpow(long int a, long int n, long int mod) {
    long int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

long int modcomb(long int a, long int b, long int mod){
    long int res = 1;
    for(long int i = a; i > a - b; i--){
        res *= i % mod;
        res %= mod;
    }
    res %= mod;
    for(long int i = 1; i <= b; i++){
        long int i_inv = modpow(i, mod - 2, mod);
        res *= i_inv % mod;
        res %= mod;
    }
    res %= mod;
    // cout << res << endl;
    return res;
}

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    ll mod = 1000000007;
    ll combx = modcomb(n * m - 2, k - 2, mod);
    ll comby = modcomb(n * m - 2, k - 2, mod);
    ll ans = 0;
    rep(i, n){
        ans += (((((i * (n - i)) % mod) * m) % mod * m) % mod) * combx;
        ans %= mod;
    }
    rep(i, m){
        ans += (((((i * (m - i)) % mod) * n) % mod * n) % mod) * comby;
        ans %= mod;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    LL(n,m);
    ll ans=1,Msqrt=sqrt(m);
    for(ll i=1;i<=Msqrt;i++){
        if(m%i==0){
            if(i*n<=m)ans=max(ans,i);
            if((m/i)*n<=m)ans=max(ans,m/i);
        }
    }
    out(ans);
}


#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int ans = 1e9;
  for (int i = 0; i < s.size() - 2; i++) {
    ans = min(ans, abs(753 - atoi((s.substr(i, 3)).c_str())));
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    std::string s;
    std::getline(std::cin, s);
    std::vector<bool> dict(26, false);
    for (char c : s)
        dict[c - 'a'] = true;
    std::string r = "None";
    for (std::size_t i = 0; i < dict.size(); ++i) {
        if (!dict[i]) {
            r = i + 'a';
            break;
        }
    }
    std::cout << r << std::endl;

    return 0;
}


#include <iostream>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	long long N;
	cin >> N;
	long long result = 0;

	for(long long i = 1;i<=N;i++){
		if(i % 3 != 0 && i % 5 != 0){
			result += i;
		}

	}

	std::cout << result << endl;
	return 0;

}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<string,int>;

int main() {
    map<string,int> day{P("SUN",7),P("MON",6),P("TUE",5),P("WED",4),P("THU",3),P("FRI",2),P("SAT",1)};
    string S;cin>>S;
    cout<<day[S]<<endl;
}

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

int main(){
  vector<string> D = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string S;
  cin >> S;
  int ans=0;
  rep(i,7){
    if(D[i]==S) ans = 7-i;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
 double U = 3.14;
 int R;
cin >> R  >> U;
 cout <<  R * 2 * U <<"\n";
}

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

int main(){
    int R;
    cin >> R;
    R *= 2;
    cout << R * 3.14 << endl;
}


// 2020-07-18 10:56:41
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const ll INF = 1e18;
void answer() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  int k = n%2+1;
  vector<ll> dp(k+1, -INF);
  dp[0] = 0;
  rep(i, n) {
    vector<ll> p(k+1, -INF);
    swap(p, dp);
    repc(j, k) {
      if(j<k) chmax(dp[j+1], p[j]);
      if((i+j)%2) {
        chmax(dp[j], p[j]);
      } else {
        chmax(dp[j], p[j] + a[i]);
      }
    }
  }
  cout << dp[k] << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,m,a,b,i,j,jc[200005],ny[200005],ans;
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long C(long long u,long long v){
	return jc[u]*ny[v]%mo*ny[u-v]%mo;
}
long long Q(long long u,long long v){
	return C(u+v,v);
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    n=read();m=read();a=read();b=read();
    jc[0]=1;
    for(i=1;i<=n+m;i++)
   		jc[i]=jc[i-1]*i%mo;
   	ny[n+m]=ksm(jc[n+m],mo-2);
   	for(i=n+m-1;i>=0;i--)
   		ny[i]=ny[i+1]*(i+1)%mo;
   	ans=Q(n-1,m-1);
   	for(i=1;i<=b;i++)
   		ans=(ans-Q(n-a-1,i-1)*Q(a-1,m-i)%mo+mo)%mo;
   	pus(ans,2);
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
#ifndef MAX
#define MAX 400000
#endif

//Range Update Query+Range Sum Query
template<class T>
class RUQ_RSQ {
public:
	int n;
	T dat[MAX], lazy[MAX], ZERO, DEFAULT;
	void init(int n_, T d = INT_MAX, T t = 0) {
		DEFAULT = d;
		ZERO = T();
		n = 1; while (n < n_)n <<= 1;
		for (int i = 0; i < 2 * n - 1; i++) {
			dat[i] = t; lazy[i] = DEFAULT;
		}
	}
	inline void push(int k, int s) {
		if (lazy[k] == DEFAULT)return;
		dat[k] = lazy[k] * s;
		if (k < n - 1) {
			lazy[k * 2 + 1] = lazy[k];
			lazy[k * 2 + 2] = lazy[k];
		}
		lazy[k] = DEFAULT;
	}
	inline void update_node(int k) {
		dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
	}
	inline void update(int a, int b, T x, int k, int l, int r) {
		push(k, r - l);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] = x; push(k, r - l); return;
		}
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		update_node(k);
	}
	inline T query(int a, int b, int k, int l, int r) {
		push(k, r - l);
		if (r <= a || b <= l)return ZERO;
		if (a <= l&&r <= b)return dat[k];
		T lb = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T rb = query(a, b, k * 2 + 2, (l + r) / 2, r);
		update_node(k);
		return lb + rb;
	}
	inline void update(int a, int b, T x) {
		update(a, b, x, 0, 0, n);
	}
	inline void update(int a, T x) {
		update(a, a + 1, x);
	}
	inline T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
	inline T query(int a) {
		return query(a, a + 1);
	}
};
RUQ_RSQ<int>seg;
int main() {
	int n, q; scanf("%d%d", &n, &q);
	seg.init(n, INT_MAX, INT_MAX);
	rep(i, q) {
		int a; scanf("%d", &a);
		if (a == 0) {
			int s, t, x; scanf("%d%d%d", &s, &t, &x); t++;
			seg.update(s, t, x);
		}
		else {
			int t; scanf("%d", &t);
			printf("%d\n", seg.query(t));
		}
	}
}

#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

#define MAX_V 100001
#define INF (1e9 + 1)

int V,E,r,a,b,c;
vector<int> Gto[MAX_V];
vector<int> Gcost[MAX_V];

int d[MAX_V];
void dijkstra(){
  int i;
  for(i=0;i<MAX_V;i++)d[i]=INF;
  d[r]=0;
  priority_queue< pair<int,int> > Q;
  Q.push( make_pair(0,r) );
  while(!Q.empty()){
    pair<int,int> p=Q.top();
    Q.pop();
    int pos=p.second,cost=-p.first;
    if( cost > d[pos] )continue;
    for(i=0;i<Gto[pos].size();i++){
      int to=Gto[pos][i];
      int newcost=cost+Gcost[pos][i];
      if( newcost < d[to]){
        d[to]=newcost;
        Q.push( make_pair(-d[to],to) );
      }
    }
  }

  for(i=0;i<V;i++){
    if(d[i]==INF)printf("INF\n");
    else printf("%d\n",d[i]);
  }
}

int main(){
  int i;
  scanf("%d %d %d",&V,&E,&r);
  for(i=0;i<E;i++){
    scanf("%d %d %d",&a,&b,&c);
    Gto[a].push_back(b);
    Gcost[a].push_back(c);
  }
  dijkstra();
  return 0;
}


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

int main(){
 string s1,s2;
  cin>>s1>>s2;
  cout<<s2+s1<<endl;
}

#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int v = 1;
    rep(i, n) {
        v = min(v * 2, v + k);
    }
    put(v)

    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int n, m;
  while(1){
    scanf("%d%d", &n, &m);
    if(n == 0 && m == 0)return 0;
    int res = 0, tmp;
    vector<int> points, points2;
    for(int i = 0;i < n;i++){
      scanf("%d", &tmp);
      if(tmp < m)points.push_back(tmp);
    }
    vector<int>::iterator it1,it2;
    for(it1 = points.begin();it1 != points.end();it1++){
      points2.push_back(*it1);
      for(it2 = points.begin();it2 != points.end();it2++){
	if(*it1 + *it2 <= m)points2.push_back(*it1 + *it2);
      }
    }
    sort(points2.begin(),points2.end());
    for(it1 = points2.begin();it1 != points2.end();it1++){
      it2 = upper_bound(points2.begin(), points2.end(), m - *it1);
      res = max(res, *it1);
      if(it2 == points2.begin())continue;
      it2--;
      res = max(res, *it1 + *it2);
    }
    printf("%d\n",res);
  }
}

//JOI 2008??´???3??? ?????????

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define MAX -210000000
#define MIN 210000000

int a,b;
int d[1002],c[1001*1001],hk=0,mcunt,low,high;
int x,pr=0/*,flg[200000000]*/,m,ff=0;

int main(){

	scanf("%d %d",&a,&b);
	while(a!=0 && b!=0){
		d[0]=0;
		hk=0;
		ff=0;
		pr=0;
		for(int i=1;i<=a;i++) scanf("%d",&d[i]);

		for(int i=0;i<=a;i++){
			for(int j=0;j<=a;j++){
				c[hk]=d[i]+d[j];
				hk++;
			}
		}
		sort(c,c+hk);
		for(int i=0;i<hk;i++){
			x=b-c[i];
			low=0;
			high=hk-1;
			while(low<=high){
				m=(low+high)/2;
				if(x==c[m]){
					ff=1;
					break;
				}
				if(x>c[m]) low=m+1;
				else if(x<c[m]) high=m-1;
			}
			if(ff==1){
				pr=c[i]+c[m];
				break;
			}
			if(b>c[i]+c[high] && pr<c[i]+c[high]){
				pr=c[i]+c[high];
			}
		}
		printf("%d\n",pr);
		scanf("%d %d",&a,&b);
	}
	return 0;
}


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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    double n; cin >> n;
    cout << 3.1415 * 2 * n;
    return 0;
}

// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    double rad;

    while(cin >> rad)
    {
		cout << setprecision(10) << fixed << 2.0 * acos(-1.0) * rad << "\n";
    }

}


#include<bits/stdc++.h>
using namespace std;
#define NIL 2000000001
typedef struct{
  int p,l,r,key;
}node;

node tree[500001];
queue<int> q[2];
int root=NIL;

void insert(int key,int i){
  node z={NIL,NIL,NIL,key};
  int x=(root==NIL?NIL:root),y=NIL;
  if(root==NIL)root=i;
  while(x!=NIL){
    y=x;
    if(z.key<tree[x].key){
      x=tree[x].l;
    }else{
      x=tree[x].r;
    }
  }
  z.p=y;
  if(y==NIL){
    tree[0]=z;
  }else if(z.key<tree[y].key){
    tree[y].l=i;
  }else {
    tree[y].r=i;
  }
  tree[i]=z;
}

void print(int n=0){
  if(n==NIL)return;
  q[1].push(tree[n].key);
  print(tree[n].l);
  q[0].push(tree[n].key);
  print(tree[n].r);
}

int find(int key){
  int f=-1,x=root;
  while(x!=NIL){
    if(tree[x].key>key){
      x=tree[x].l;
    }else if(tree[x].key<key){
      x=tree[x].r;
    }else{
      f=x;
      break;
    }
  }
  return f;
}

void del(int k){
  int x=find(k);
  if(x==-1)return;
  if(tree[x].l==NIL&&tree[x].r==NIL){

    if(tree[tree[x].p].l==x){
      tree[tree[x].p].l=NIL;
    }else{
      tree[tree[x].p].r=NIL;
    }

  }else if(tree[x].l==NIL||tree[x].r==NIL){

    if(tree[x].l==NIL){
      if(tree[tree[x].p].l==x){
	tree[tree[x].r].p=tree[x].p;
	tree[tree[x].p].l=tree[x].r;
      }else{
	tree[tree[x].r].p=tree[x].p;
	tree[tree[x].p].r=tree[x].r;
      }
    }else{
      if(tree[tree[x].p].l==x){
	tree[tree[x].l].p=tree[x].p;
	tree[tree[x].p].l=tree[x].l;
      }else{
	tree[tree[x].l].p=tree[x].p;
	tree[tree[x].p].r=tree[x].l;
      }
    }
  }else{
    int dx=tree[x].r;
    while(tree[dx].l!=NIL)dx=tree[dx].l;
    tree[x].key=tree[dx].key;
    if(tree[dx].l==NIL&&tree[dx].r==NIL){

      if(tree[tree[dx].p].l==dx){
	tree[tree[dx].p].l=NIL;
      }else{
	tree[tree[dx].p].r=NIL;
      }

    }
    else{
      if(tree[dx].l==NIL){
	if(tree[tree[dx].p].l==dx){
	  tree[tree[dx].r].p=tree[dx].p;
	  tree[tree[dx].p].l=tree[dx].r;
	}else{
	  tree[tree[dx].r].p=tree[dx].p;
	  tree[tree[dx].p].r=tree[dx].r;
	}
      }else{
	if(tree[tree[dx].p].l==dx){
	  tree[tree[dx].l].p=tree[dx].p;
	  tree[tree[dx].p].l=tree[dx].l;
	}else{
	  tree[tree[dx].l].p=tree[dx].p;
	  tree[tree[dx].p].r=tree[dx].l;
	}
      }
    }
  }
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string a;
    cin>>a;

    if(a[0]=='i'){
      int k;
      cin>>k;
      insert(k,i);

    }else if(a[0]=='f'){
      int key;
      cin>>key;
      cout<<(find(key)>=0?"yes":"no")<<endl;
    }else if(a[0]=='d'){
      int key;
      cin>>key;
      del(key);
    }else{
      print();
      for(int j=0;j<2;j++){
	while(!q[j].empty()){
	  cout<<" "<<q[j].front();
	  q[j].pop();
	}
	cout<<endl;
      }
    }
  }
  return 0;
}

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int k;
  cin>>k;

  int r,c;
  vector<int> A(8),B(8);
  rep(i,8) A[i]=i;
  rep(i,8) B[i]=-1;
  rep(i,k){
    cin>>r>>c;
    B[r]=c;
  }

  char C[8][8];
  rep(i,8){
    rep(j,8) C[i][j]='.';
  }

  set<int> p,q;
  do{
    bool b=true;
    rep(i,8){
      if(B[i]!=-1 && B[i]!=A[i]) b=false;
    }
    if(b==false) continue;
    rep(i,8) p.insert(i+A[i]);
    rep(i,8) q.insert(i-A[i]);
    if(p.size()!=8 || q.size()!=8){
      p.clear(); q.clear();
      continue;
    }
    rep(i,8) C[i][A[i]]='Q';
    break;
  }while(next_permutation(ALL(A)));

  rep(i,8){
    rep(j,8) cout<<C[i][j];
    cout<<endl;
  }

  return 0;
}


/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//223
	int n;
	cin>>n;
	unordered_set<int> s;
	while(n--) {
		int val;
		cin>>val;
		if(s.count(val)==1){
			s.erase(val);
		} else {
			s.insert(val);
		}
	}
	cout<<s.size();
}

int main() {

	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////

	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    string S;
    cin>>S;
    map<string,int> num;
    num["SUN"]=7;
    num["MON"]=6;
    num["TUE"]=5;
    num["WED"]=4;
    num["THU"]=3;
    num["FRI"]=2;
    num["SAT"]=1;

   cout<<num[S]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int cnt;
  int sum;
  string ans="War";
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  vector<int> b(m);
  rep(i,m){
    cin>>b[i];
  }
  for(int i=x+1;i<y;i++){
    cnt=0;
    for(int j=0;j<n;j++){
      if(i>a[j]) cnt++;
    }
    sum=0;
    if(cnt==n){
      for(int j=0;j<m;j++){
        if(i<=b[j]) sum++;
      }
    }
    if(sum==m) ans="No War";
  }
  cout<<ans<<endl;
}

#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;

int main()
{
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    for(int i=1;i<=b;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j<=a)
            {
                cout<<1;
            }
            else
            {
                cout<<0;
            }
        }
        cout<<endl;
    }
    for(int i=b+1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j>a)
            {
                cout<<1;
            }
            else
            {
                cout<<0;
            }
        }
        cout<<endl;
    }
    return 0;
}


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

bool bfs(int s,int t,vector<vector<pair<int,int>>> graph,vector<int> &prev)
{
	int v,w;
	vector<bool> visit(201,false);
	queue<int> que;
	que.push(s);
	visit[s]=true;
	for (int i=0;i<prev.size();i++) prev[i]=0;
	while(!que.empty())
	{
		v=que.front();
		que.pop();
		for (int i=0;i<graph[v].size();i++)
		{

			if (graph[v][i].first!=0)
			{
				w=i;
				if (!visit[w])
				{
					visit[w]=true;
					prev[w]=v;
					que.push(w);
				}
			}
		}
	}
	return visit[t];
}

int main()
{
	int N;cin>>N;
	vector<pair<int,int>> red(N),blue(N);
	vector<vector<int>> capacity(2*N+2,vector<int> (2*N+2));
	vector<vector<int>> flow(2*N+2,vector<int> (2*N+2));
	vector<vector<pair<int,int>>> network(2*N+2,vector<pair<int,int>> (2*N+2));
	int x,y;
	for (int i=0;i<N;i++)
	{
		cin >> x >> y;
		red[i].first=x;
		red[i].second=y;
		capacity[0][i+1]=1;
	}
	for (int i=0;i<N;i++)
	{
		cin >> x >> y;
		blue[i].first=x;
		blue[i].second=y;
		capacity[N+i+1][2*N+1]=1;
	}
	for (int i=0;i<N;i++)
		for (int j=0;j<N;j++)
		{
			if ((red[i].first<blue[j].first) && (red[i].second < blue[j].second))
			{
				capacity[i+1][N+j+1]=1;
			}
		}
	for (int i=0;i<2*N+2;i++)
		for (int j=0;j<2*N+2;j++)
		{
			if (capacity[i][j]>flow[i][j])
			{
				network[i][j].first=1;
				network[i][j].second=1;
			}
			if (flow[i][j]>0)
			{
				network[j][i].first=1;
				network[j][i].second=0;
			}
		}

	int to,from=-1;
	vector<int> prev(2*N+2);

	while (bfs(0,2*N+1,network,prev))
	{
		from =-1;
		to=2*N+1;
		while(from!=0)
		{
			from=prev[to];
			if (network[from][to].second==1)
			{
				flow[from][to]=1;
				network[from][to].first=0;
				network[to][from].first=1;
				network[from][to].second=1;
				network[to][from].second=0;
			}
			else
			{
				flow[from][to]=0;
				network[from][to].first=0;
				network[to][from].first=1;
				network[from][to].second=0;
				network[to][from].second=1;
			}
			to=from;
		}
	}

	int ans=0;
	for (int i=1;i<2*N+1;i++) ans+=flow[i][2*N+1];
	cout << ans << endl;

return 0;
}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,m,dp[110][110][110],sum[110][110],ans;
char s[110];bool a[110][110];
int getsum(int l,int r,int u,int d){
//	cout<<"		getsum "<<l<<' '<<r<<' '<<u<<' '<<d<<' '<<sum[r][d]-sum[l-1][d]-sum[r][u-1]+sum[l-1][u-1]<<'\n';
	return sum[d][r]-sum[d][l-1]-sum[u-1][r]+sum[u-1][l-1];
}
int main(){
//	freopen("1.in","r",stdin);
	int l,r,u,d,i,j,liml,limr,limu,limd,edx,edy;
	n=read();m=read();
	for(i=1;i<=n;i++){
		scanf("%s",s);
		for(j=0;j<m;j++){
			if(s[j]=='o') a[i][j+1]=1;
			if(s[j]=='E') edx=i,edy=j+1;
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+a[i][j];
//			cout<<i<<' '<<j<<' '<<sum[i][j]<<'\n';
		}
	}
	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++){
			for(l=0;l<=n;l++){
				dp[i][j][l]=-1e9;
			}
		}
	}
	dp[0][0][0]=0;
//	cout<<"start "<<edx<<' '<<edy<<'\n';
	for(l=0;l<m;l++){
		if(edy-l<=0) break;
		for(r=0;r<m;r++){
			if(edy+r>m) break;
			liml=max(edy-l,1+r);
			limr=min(edy+r,m-l);
			if(liml>limr) continue;
			for(u=0;u<n;u++){
				if(edx-u<=0) break;
				for(d=0;d<n;d++){
					if(edx+d>n) break;
					limu=max(edx-u,1+d);
					limd=min(edx+d,n-u);
					if(limu>limd) continue;
//					cout<<l<<' '<<r<<' '<<u<<' '<<d<<' '<<dp[r][u][d]<<'\n';
//					if(dp[r][u][d]==-1) continue;
					ans=max(ans,dp[r][u][d]);
					if(edy+r+1<=m-l){
//						cout<<"	type 1 "<<l<<' '<<r+1<<' '<<u<<' '<<d<<'\n';
						dp[r+1][u][d]=max(dp[r+1][u][d],dp[r][u][d]+getsum(edy+r+1,edy+r+1,limu,limd));
					}
					if(edx-u-1>=1+d){
//						cout<<"	type 2 "<<l<<' '<<r<<' '<<u+1<<' '<<d<<'\n';
						dp[r][u+1][d]=max(dp[r][u+1][d],dp[r][u][d]+getsum(liml,limr,edx-u-1,edx-u-1));
					}
					if(edx+d+1<=n-u){
//						cout<<"	type 3 "<<l<<' '<<r<<' '<<u<<' '<<d+1<<'\n';
						dp[r][u][d+1]=max(dp[r][u][d+1],dp[r][u][d]+getsum(liml,limr,edx+d+1,edx+d+1));
					}
					if(edy-l-1>=1+r){
//						cout<<"	type 4 "<<l+1<<' '<<r<<' '<<u<<' '<<d<<'\n';
						dp[r][u][d]=max(dp[r][u][d],dp[r][u][d]+getsum(edy-l-1,edy-l-1,limu,limd));
					}
				}
			}
		}
	}
	cout<<ans;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int n;  cin >> n;
  vector<long long>a(n);  for(int i=0;i<n;i++)  cin >> a.at(i);
  vector<long long>b(n);  for(int i=0;i<n;i++)  cin >> b.at(i);
  vector<long long>c(n);  for(int i=0;i<n;i++)  cin >> c.at(i);
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());

  long long ans = 0;
  for(int i=0;i<n;i++){
    auto Iter = lower_bound(a.begin(),a.end(),b.at(i));
    long long count_a = Iter - a.begin();

    Iter = upper_bound(c.begin(),c.end(),b.at(i));
    long long count_c = n - (Iter - c.begin());

    ans += count_a * count_c;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int main(){
  int n,l; cin>>n>>l;
  vector<pair<int, bool> > fla;
  for (size_t i = 0; i < n; i++)
  {
    int tmpfl = l + i;
    if (tmpfl< 0)
    {
      tmpfl *= -1;
      fla.push_back(make_pair(tmpfl , true));
      continue;
    }
    fla.push_back(make_pair(tmpfl , false));

  }
  sort(fla.begin(), fla.end());

  fla.erase(fla.begin());
  ll ans =0;
  for (auto &&i : fla)
  {
    ans += i.second ? -1 * i.first : i.first ;
  }
  cout << ans << endl;
}


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

typedef long long ll;

ll cou;

void merge(vector<ll> &v,ll l,ll r){
    ll mid = (r+l)/2;
    ll n1 = mid-l;
    ll n2 = r-mid;
    vector<ll> a,b;
    for(ll i=0;i<n1;i++)a.push_back(v[l+i]);
    for(ll i=0;i<n2;i++)b.push_back(v[mid+i]);
    a.push_back(1e9);
    b.push_back(1e9);
    ll aa=0,bb=0;
    for(ll i=l;i<r;i++){
        if(a[aa]<b[bb]){
            v[i]=a[aa++];
        }else{
            v[i]=b[bb++];
            cou+=n1-aa;
        }
    }
}
void merge_sort(vector<ll> &v,ll l,ll r){
    if(r-l>1){
        ll mid = (r+l)/2;
        merge_sort(v,l,mid);
        merge_sort(v,mid,r);
        merge(v,l,r);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)cin >> a[i];
    merge_sort(a,0,n);
    cout << cou << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e6+5;
int a[maxm];
int n;
signed main(){
    cin>>n;
    for(int i=1;i<=n*2;i++)cin>>a[i];
    int ans=0;
    sort(a+1,a+1+n*2);
    for(int i=1;i<=n*2;i+=2){
        ans+=min(a[i],a[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n-r+1;
	int sum = 1;
	for(int i =s;i<=n;i++)
		sum *= i;
	return sum;
}
//int nCr1(int n, int r)
//int nCr2(int n, int r)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int K, N;
	cin >> K >> N;
	cout << K - N + 1;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int N;
  int K;
  rd(N);
  rd(K);
  wt_L(N-K+1);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// {
//   int N, K;
//   rd(N,K);
//   wt(N-K+1);
// }


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[20][20];
int d[(1 << 16)];
vector<int> vec;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)cin >> a[i][j];
	for (int i = 1; i < (1 << n); i++) {
		vec.clear();
		for (int j = 0; j < n; j++)if (i&(1 << j))vec.push_back(j);
		int m = (int)vec.size();
		int ma = 0;
		for (int j = 0; j < (int)vec.size(); j++)for (int k = j + 1; k < (int)vec.size(); k++)ma += a[vec[j]][vec[k]];
		for (int j = 0; j < (1 << m); j++) {
			int cnt = 0;
			for (int k = 0; k < m; k++)if (j&(1 << k))cnt += (1 << vec[k]);
			ma = max(ma, d[cnt] + d[i - cnt]);
		}
		d[i] = ma;
	}
	cout << d[(1 << n) - 1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  long long L[N], R[N];
  for (int i = 0; i < N; i++) cin >> L[i] >> R[i];
  int idx[N];
  iota(idx, idx + N, 0);
  // debugArray(idx, N);
  auto step = [&]() {
    long long leftl[N + 1], leftr[N + 1], rightl[N + 1], rightr[N + 1];
    leftl[0] = 0, leftr[0] = INT_MAX;
    for (int i = 0; i < N; i++) {
      int j = idx[i];
      leftl[i + 1] = max(leftl[i], L[j]);
      leftr[i + 1] = min(leftr[i], R[j]);
    }
    rightl[N] = 0, rightr[N] = INT_MAX;
    for (int i = N - 1; i >= 0; i--) {
      int j = idx[i];
      rightl[i] = max(rightl[i + 1], L[j]);
      rightr[i] = min(rightr[i + 1], R[j]);
    }
    // debugArray(leftl, N + 1);
    // debugArray(leftr, N + 1);
    // debugArray(rightl, N + 1);
    // debugArray(rightr, N + 1);
    long long ret = 0;
    for (int i = 0; i < N - 1; i++) {
      ret = max(ret, max(0ll, leftr[i + 1] - leftl[i + 1] + 1)
                         + max(0ll, rightr[i + 1] - rightl[i + 1] + 1));
    }
    for (int i = 0; i < N; i++) {
      int j = idx[i];
      int ll = max(leftl[i], rightl[i + 1]);
      int rr = min(leftr[i], rightr[i + 1]);
      ret = max(ret, max(0, rr - ll + 1) + R[j] - L[j] + 1);
    }
    return ret;
  };
  long long ans = 0;
  sort(idx, idx + N,
       [&](int l, int r) { return L[l] == L[r] ? R[l] > R[r] : L[l] < L[r]; });
  ans = max(ans, step());
  sort(idx, idx + N,
       [&](int l, int r) { return R[l] == R[r] ? L[l] > L[r] : R[l] < R[r]; });
  ans = max(ans, step());
  cout << ans << '\n';
  return 0;
}


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

typedef long long LL;

const int N = 25;

int d;
LL p[N];
int sub1[N], sub2[N];      // sub1 not front, sub2 is front

vector <LL> v;

void dfs(int s, int e, vector <pair <LL, LL> > &w, LL val, LL cnt){
    if (s == e){
        w.push_back(make_pair(val, cnt));
        return ;
    }

    for (int i = -9; i < 10; i++)                     // 枚举差值
        dfs(s + 1, e, w, val + i * v[s], cnt * (s ? sub1[i + 10] : sub2[i + 10]));
}

LL solve(int len){
    v.clear();
    for (int i = 0; i < len - 1 - i; i++) v.push_back(p[len - 1 - i] - p[i]);

    vector <pair <LL, LL> > v1, v2;
    dfs(0, (v.size() + 1) >> 1, v1, 0, 1);
    dfs((v.size() + 1) >> 1, v.size(), v2, 0, 1);

    LL ans = 0;
    map <LL, LL> mp;
    for (int i = 0; i < v2.size(); i++) mp[v2[i].first] += v2[i].second;
    for (int i = 0; i < v1.size(); i++) ans += mp[d - v1[i].first] * v1[i].second;

    if (len & 1) ans *= 10;
    return ans;
}

int main(){
    p[0] = 1;
    for (int i = 1; i < 20; i++) p[i] = p[i - 1] * 10;
    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++) sub1[i - j + 10]++;
    for (int i = 0; i < 10; i++)
        for (int j = 1; j < 10; j++) sub2[i - j + 10]++;

    scanf("%d", &d);
    LL ans = 0;
    for (int i = 2; i <= 18; i++) ans += solve(i);

    printf("%lld", ans);

    return 0;
}

#include <iostream>
#include <vector>
using namespace std;
long long MOD = 1e9 + 7;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<long long> cnt(60, 0);
    for(int i = 0; i < N; i++){
        int cn = 0;
        long long t = A[i];
        while(t > 0){
            if(t % 2 == 1) cnt[cn]++;
            cn++;
            t >>= 1;
        }
    }
    long long ans = 0;
    for(int i = 0; i < 60; i++){
        ans += (1LL << i) % MOD * cnt[i] % MOD * (N - cnt[i]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD=1e9+7;
int n,x[3], dp[40][1<<16];
void printbin(int n, int b = 31) {
	for(int i=b-1; i>=0; i--) printf("%d", n>>i&1);
}
int Count(int p, int b) {
	if(p==n) return 1;
	int& res=dp[p][b];
	if(res!=-1) return res;
	res=0;
	int i,t=b,c=0,f=0;
	bool chk[11]={0};
	while(t>0) t>>=1,c++;
	for(i=0;i<c;i++) {
		if(i&&(~b>>(i-1)&1)) continue;
		if(~b>>(i+x[0]-1)&1) continue;
		if(~b>>(i+x[0]+x[1]-1)&1) continue;
		t=i+x[0]+x[1]+x[2]-c;
		if(t>=1&&t<=10)
			chk[t]=1;
	}
	t=b;
	for(int i=1;i<=10;i++) {
		if(chk[i]) continue;
		while(c+i>16) {
			while(t>0&&!(t&1))t>>=1,c--;
			t>>=1,c--;
		}
		res=(res+Count(p+1,t|(1<<(c+i-1))))%MOD;
	}
	//printf("dp[%d][%d]:%d\n",p,b,res);
	//printf("dp[%d][",p); printbin(b,16); printf("]:%d\n",res);
	return res;
}
int main() {
	memset(dp,-1,sizeof(dp));
	scanf("%d%d%d%d",&n,x,x+1,x+2);
	int p=1;
	for(int i=1;i<=n;i++) p=10ll*p%MOD;
	printf("%d", (p-Count(0,0)+MOD)%MOD);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
#define endl "\n";
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>

int solve(int st, vi a, int& ans,int& n){
	if(st > n ) return 0;
	int res = 0;
	int x1 = solve(st*2, a, ans, n);
	int x2 = solve(st*2+1, a, ans, n);
	int l1 = (st*2-2)>=a.size()?0:a[st*2-2];
	int l2 = (st*2-1)>=a.size()?0:a[st*2-1];
	l2 += x2; l1+=x1;
	ans += abs(l2-l1);
	return max(l1,l2);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	int a, b;
	cin >> a>> b;
	cout << (ll) a*b << endl;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int a,b; cin >> a >> b;
    int h = 100, w = 100;
    // int h = 10, w = 10;
    // vector<string> s(h);
    string s[h];
    rep(i,h)rep(j,w){
        if(i*2 < h)s[i] += '#';
        else s[i] += '.';
    }
    int cnt = 0;
    int x = 0, y = 0;
    int dx[8] = {0,0,1,-1,1,-1,1,-1};
    int dy[8] = {-1,1,0,0,1,-1,-1,1};
    while(cnt < a-1){
        bool ok = true;
        rep(i,8){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && h > nx && ny >= 0 && w > ny){
                if(s[nx][ny] == '.')ok = false;
            }
        }
        if(ok){
            s[x][y] = '.';
            ++cnt;
        }
        if(y < w-1)++y;
        else{y = 0;++x;}
    }

    x = h-1;
    y = w-1;
    cnt = 0;
    while(cnt < b-1){
        bool ok = true;
        rep(i,8){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && h > nx && ny >= 0 && w > ny){
                if(s[nx][ny] == '#')ok = false;
            }
        }
        if(ok){
            s[x][y] = '#';
            ++cnt;
        }
        if(0 < y)--y;
        else{y = w-1;--x;}
    }
    cout << h << " " << w << endl;
    rep(i,h){
        rep(j,w)cout << s[i][j];
        cout << "\n";
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;
vector<int> adj[N];
int vis[N] , n;

bool cycle(int node , int lim) {
    if (vis[node])
        return vis[node] == 1;

    if (!lim)
        return 0;

    vis[node] = 1;
    for (int c : adj[node])
        if (cycle(c , lim - 1))
            return 1;
    vis[node] = 2;

    return 0;
}

vector<int> sec;
void find_ans(int node , int lim) {
    if (vis[node] == 2)
        return;

    if (vis[node] == 1) {
        for (int c : sec)
            cout << c << '\n';
        exit(0);
    }

    if (!lim)
        return;

    sec.push_back(node);
    vis[node] = 1;

    for (int c : adj[node])
        find_ans(c , lim - 1);

    vis[node] = 2;
    sec.pop_back();
}

bool good(int lim) {
    for (int st = 1 ; st <= n ; st++) {
        memset(vis , 0 , sizeof vis);
        if (cycle(st , lim))
            return 1;
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    int m;
    cin >> n >> m;

    while (m--) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    int l = 2 , r = n , ans = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (good(mid)) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    cout << ans;
    if (~ans) {
        cout << '\n';
        for (int st = 1 ; st <= n ; st++) {
            memset(vis , 0 , sizeof vis);
            if (cycle(st , ans)) {
                memset(vis , 0 , sizeof vis);
                find_ans(st , ans);
                return 0;
            }
        }
    }
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){

	string str;
	cin >> str;
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		string command;
		int a, b;
		cin >> command >> a >> b;
		if(command == "print"){
			cout << str.substr(a, b-a+1) << endl;
		}
		if(command == "reverse"){
			reverse(str.begin()+a, str.begin()+b+1);
		}
		if(command == "replace"){
			string p;
			cin >> p;
			str.replace(a, b-a+1, p);
		}
	}
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A);
	vector<int> b(B);
	vector<int> x(M);
	vector<int> y(M);
	vector<int> c(M);
	for (int i = 0; i < A; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> x[i] >> y[i] >> c[i];
	}
	int value = 1000000;
	for (int i = 0; i < M; i++) {
		value = min(value, a[x[i] - 1] + b[y[i] - 1] - c[i]);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	value = min(value, a[0] + b[0]);
	cout << value << endl;
	return 0;
}


#include <stdio.h>
int main() {
	int n;
	long long int val = 0;
	scanf("%d",&n);

	for (int i = 1 ; i <= n; i++)
	{
		if (i % 3 == 0 && i % 5 == 0)
		{
			continue;
		}
		else if (i % 3 == 0)
		{
			continue;
		}
		else if (i % 5 == 0)
		{
			continue;
		}
		else
		{
			val += i;
		}
	}
	printf("%lld",val);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}


#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> Vi;
typedef pair<int,int> pii;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=1e5+19;

int A[3][N];
int n,rev[2];
Vi V[2];

int C[N];
void Add(int x){
	for (;x<N;x+=x&-x) C[x]++;
}
int Qry(int x){
	int res=0;
	for (;x;x-=x&-x) res+=C[x];
	return res;
}
ll calc(int t){
	ll res=0;
	memset(C,0,sizeof(C));
	for (int i=V[t].size()-1;~i;i--){
		res+=Qry(V[t][i]+1);
		Add(V[t][i]+1);
	}
	return res;
}

int main(){
	n=IN();
	For(i,0,3) For(j,0,n) A[i][j]=IN()-1;
	For(i,0,3) For(j,0,n){
		if (A[i][j]/3!=A[0][j]/3) return puts("No"),0;
		if ((A[i][j]/3)%2!=j%2) return puts("No"),0;
	}
	For(i,0,n){
		if (A[1][i]%3!=1) return puts("No"),0;
		if (A[0][i]%3!=0) rev[i&1]++;
		V[i&1].pb(A[0][i]/3);
	}
	if (calc(0)%2!=rev[1]%2) return puts("No"),0;
	if (calc(1)%2!=rev[0]%2) return puts("No"),0;
	puts("Yes");
}


#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, sum = 0; cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vector<pair<ll, ll>> ab(n, {0, 0});
    rep(i, n){
        ab[i].first = a[i]+b[i];
        ab[i].second = i;
    }
    sort(all(ab), greater<pair<ll, ll>>());
    rep(i, n){
        if(i%2 == 0) sum += a[ab[i].second];
        else sum -= b[ab[i].second];
    }
    cout << sum << endl;
}

#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n;
	cin >> n;
	vector<vector<P>>lis(n);
	rep(i, n) {
		int a;
		cin >> a;
		rep(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			lis[i].push_back(P(x, y));
		}
	}
	int ans(0);
	for (int bit = 0; bit < (1 << n); ++bit) {
		int c = 0;
		int can = 0;
		rep(i, n) {
			int cnt(0);
			int a = lis[i].size();
			if (!(bit >> i & 1))continue;
			can++;
			rep(j, lis[i].size()) {
				int x = lis[i][j].first; int y = lis[i][j].second;
				if ((bit >> x & 1) && y != 1)cnt++;
				if (!(bit >> x & 1) && y == 1)cnt++;
			}
			if (cnt >= 1)c = -1;
		}
		//cout << bit << can << endl;
		if (c != -1) {
			ans = max(can, ans);
		}

	}
	cout << ans;
	return 0;
}


#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>

using namespace std;

int t[5];

bool straight()
{
	if(t[0] == 1 && t[1] == 10 && t[2] == 11 && t[3] == 12 && t[4] == 13) return true;
	for (int i = 0; i < 4; i++){
		if(t[i+1]-t[i] != 1) return false;
	}
	return true;
}

int main()
{
	while(~scanf("%d,%d,%d,%d,%d",t,t+1,t+2,t+3,t+4)){
		sort(t,t+5);
		if(t[0] == t[3] || t[1] == t[4])
			puts("four card");
		else if( (t[0] == t[1] && t[2] == t[4]) || (t[0] == t[2] && t[3] == t[4]))
			puts("full house");
		else if(straight())
			puts("straight");
		else if(t[0] == t[2] || t[1] == t[3] || t[2] == t[4])
			puts("three card");
		else if( (t[0] == t[1] && (t[2] == t[3] || t[3] == t[4])) || (t[1] == t[2] && t[3] == t[4]) )
			puts("two pair");
		else if( t[0] == t[1] || t[1] == t[2] || t[2] == t[3] || t[3] == t[4])
			puts("one pair");
		else
			puts("null");
	}
	return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n;
  int dp[31];
  dp[1] = 1;
  dp[2] = 2;
  dp[3] = 4;
  for ( int i = 4; i <= 30; i++ ) dp[i] = dp[i-1] + dp[i-2] + dp[i-3];

  while ( cin >> n, n ) {
    cout << dp[n]/10/365 + 1 << endl;
  }

  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int dx[] = {0, -1, 0, 1};
const int dy[] = {-1, 0, 1, 0};

bool fill(vector<vector<int> > &v, int x, int y, int gx, int gy) {
    if(x == gx && y == gy) return true;

    int W = v.size();
    int H = v[0].size();
    int clr = v[x][y];
    v[x][y] = 0;

    for(int i = 0; i < 4; ++i) {
        int xx = x + dx[i];
        int yy = y + dy[i];

        if(0 <= xx && xx < W && 0 <= yy && yy < H) {
            if(v[xx][yy] == clr) {
                if(fill(v, xx, yy, gx, gy)) return true;
            }
        }
    }
    return false;
}

int main() {
    while(true) {
        int W, H;
        int sx, sy, gx, gy;
        int N;

        cin >> W >> H;
        if(!W && !H) break;
        cin >> sx >> sy >> gx >> gy >> N;
        --sx; --sy; --gx; --gy;

        vector<vector<int> > v(W, vector<int>(H, 0));
        for(int i = 0; i < N; ++i) {
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            --x; --y;
            int w = d ? 2 : 4;
            int h = d ? 4 : 2;
            for(int dx = 0; dx < w; ++dx)
                for(int dy = 0; dy < h; ++dy)
                    v[x+dx][y+dy] = c;
        }

        if(v[sx][sy] != 0 && fill(v, sx, sy, gx, gy)) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}

#include <cstdio>
#include <functional>
#include <vector>
#include <algorithm>

int testcase_ends() {
  int w, h;
  scanf("%d %d", &w, &h);
  if (w == 0 && h == 0)
    return 1;

  int xs, ys;
  scanf("%d %d", &xs, &ys);

  int xg, yg;
  scanf("%d %d", &xg, &yg);

  std::vector<std::vector<int>> g(h+2, std::vector<int>(w+2));

  int n;
  scanf("%d", &n);

  for (int i=0; i<n; ++i) {
    int c, d, x, y;
    scanf("%d %d %d %d", &c, &d, &x, &y);

    int dh=2, dw=2;
    (d? dh:dw) += 2;

    for (int j=0; j<dh; ++j)
      for (int k=0; k<dw; ++k)
	g[y+j][x+k] = c;
  }

  // for (int i=0; i<h; ++i)
  //   for (int j=0; j<w; ++j)
  //     fprintf(stderr, "%d%c", g[i][j], j+1<w? ' ':'\n');

  if (g[ys][xs] != g[yg][xg])
    return !printf("NG\n");

  const int dy[]={-1, 0, 1, 0};
  const int dx[]={0, -1, 0, 1};
  std::function<bool (int, int)> dfs=[&](int x, int y) {
    if (x == xg && y == yg) return true;

    int cs=g[y][x];
    g[y][x] = -cs;  // mark visited
    for (int k=0; k<4; ++k) {
      int cd=g[y+dy[k]][x+dx[k]];
      if (cs == cd && dfs(x+dx[k], y+dy[k]))
	return true;
    }
    return false;
  };

  printf("%s\n", dfs(xs, ys)? "OK":"NG");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);};
double cross(P a,P b){return imag(conj(a)*b);};

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n==0)break;
    ll cur;
    cin>>cur;
    ll mx = cur;
    while(--n){
      ll x;
      cin>>x;
      cur = max(x,cur+x);
      mx = max(mx,cur);
    }
    cout<<mx<<endl;
  }
  return 0;
}

#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n, n){
		int a[5000], ans = -100001;
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int k,n,l,i;
  int ans=(1<<29);
  cin >> n >> l;
  vector<int> x(n);
  for(i=0;i<n;i++){
    x[i]=l+(i+1)-1;
    if(abs(x[i])<ans){
      ans=abs(x[i]);
      k=x[i];
    }
  }
  for(i=0;i<n;i++){
    if(k==x[i]){
      x[i]=0;
      break;
    }
  }
  int sum=0;
  for(i=0;i<n;i++){
    sum+=x[i];
  }
  cout << sum << endl;
  return 0;
}

#include<iostream>

using namespace std;

int main()
{
	int month[12];

	month[0]=31;
	month[1]=29;
	month[2]=31;
	month[3]=30;
	month[4]=31;
	month[5]=30;
	month[6]=31;
	month[7]=31;
	month[8]=30;
	month[9]=31;
	month[10]=30;
	month[11]=31;

	int hoge,fuga;

	hoge = 1;

	int i;
	int count=0;

	while(hoge!=0)
	{
		count = 0;
		cin >> hoge >> fuga;
		//cout << count << endl;
		for(i=0;i<hoge-1;i++)
		{
			count+=month[i];
		}
		//cout << count << endl;

		count+=fuga;

		//cout << count << endl;

		int flag = 0;

		flag = count % 7;

		if(flag==0 & hoge!=0)
		{
			cout << "Wednesday" <<endl;
		}
		if(flag==1 & hoge!=0)
		{
			cout << "Thursday" <<endl;
		}
		if(flag==2 & hoge!=0)
		{
			cout << "Friday" <<endl;
		}
		if(flag==3 & hoge!=0)
		{
			cout << "Saturday" <<endl;
		}
		if(flag==4 & hoge!=0)
		{
			cout << "Sunday" <<endl;
		}
		if(flag==5 & hoge!=0)
		{
			cout << "Monday" <<endl;
		}
		if(flag==6 & hoge!=0)
		{
			cout << "Tuesday" <<endl;
		}
	}
}


#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, p;
	while (cin >> n >> p, n) {
		int now = 0,wan=p;
		vector<int>person(n,0);
		while (true) {
			if (wan) {
				person[now]++; wan--;
				if (person[now] == p) {
					cout << now << endl;
					break;
				}
			}
			else if (person[now]) {
				wan = person[now]; person[now] = 0;
			}
			now++;
			if (now >= n)now = 0;
		}
	}
}

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

int main(){
    int N, P;
    while(true){
        scanf("%d%d", &N, &P);
        if(N == 0 && P == 0) break;
        int c[50], left = P;
        fill(c, c + N, 0);
        int turn = 0;
        while(true){
            if(left == 0){
                left += c[turn];
                c[turn] = 0;
            }else{
                --left;
                c[turn] += 1;
            }
            if(c[turn] == P){
                break;
            }
            turn = (turn + 1) % N;
        }
        printf("%d\n", turn);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> prime(0);
const int M=1000;

void primeGeneration(){
  vector<bool> number(M,true);
  for(int i=2;i*i<M;i++){
    for(int j=i+i;j<=M;j+=i){
      number[j]=false;
    }
  }
  for(int i=2;i<M;i++){
    if(number[i])prime.push_back(i);
  }
};

void factorization(vector<int> &num,vector<int> &pow,int N){
  int n=0,k=-1;
  int rn=-1;
  for(int i=0;i<M;i++){
    num[i]=0;pow[i]==0;
  }
  while(true){
    if(N%prime[n]==0){
      if(rn!=n){
        k++;
        num[k]=prime[n];
      }
      pow[k]++;
      N/=prime[n];
      rn=n;
    }else{
      n++;
    }
    if(N==1)break;
    if(prime[n]*prime[n]>N){
      bool ne=true;
      for(int i=0;i<=k;i++){
        if(num[i]==N){
          pow[i]++;
          ne=false;
          break;
        }
      }
      if(ne){
        num[k+1]=N;
        pow[k+1]=1;
      }
      break;
    }
  }
};

int main() {
  primeGeneration();
  //for(int i=0;i<M;i++)cout<<prime[i]<<endl;
  int N;cin>>N;
  vector<int> pow(M,0);
  for(int i=2;i<=N;i++){
    vector<int> p(M,0);
    vector<int> n(M,0);
    factorization(n,p,i);
    int k=0;
    for(int j=0;j<prime.size();j++){
      //cout<<prime[j]<<" "<<n[k]<<endl;
      if(prime[j]==n[k]){
        pow[j]+=p[k];k++;
      }
    }
  }
  long cnt=1;
  for(int i=0;i<M;i++){
    cnt=(cnt*(pow[i]+1))%1000000007;
  }
  cout<<cnt<<endl;
}

#include <iostream>
#include <cmath>

using namespace std;

bool isprime(int n)	{
  for (int i = 2; i * i <= n; i++)	{
    if (n % i == 0)
      return false;
  }
  return true;
}

int log(int base, int num)	{
  int temp = 0;
  int base1 = base;
  while (num / base1 > 0)	{
	temp += num / base1;
    base1 *= base;
  }
  return temp;
}

int main()	{
  int n;
  cin >> n;
  long long result = 1;
  for (int i = 2; i <= n; i++)	{
    if (isprime(i))	{
	  result = (result * (log(i, n) + 1)) % 1000000007;
    }
  }
  cout << result << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int main() {
	int n;
	VI _array;
	string str;
	while ( ~scanf( "%d", &n ) && n ) {
		_array.resize( n );
		for ( int i = 0; i < n; i++ ) {
			scanf( "%d", &_array[ i ] );
			_array[ i ] %= 52;
		}
		cin >> str;
		for ( int i = 0; i < str.size(); i++ ) {
			for ( int j = 0; j < _array[ i % n ]; j++ ) {
				if ( str[ i ] - 1 < 'a' && ( str[ i ] < 'A' || str[ i ] > 'Z' ) ) {
					str[ i ] = 'Z';
				}
				else if ( str[ i ] - 1 < 'A' && ( str[ i ] < 'a' || str[ i ] > 'z' ) ) {
					str[ i ] = 'z';
				}
				else {
					str[ i ]--;
				}
			}
		}
		printf( "%s\n", str.c_str() );
	}
	return 0;
}

#include <iostream>
#include <map>
using namespace std;

string Alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int l = 52;

int main(void) {
    int n, x, d;
    int k[1000];
    string s;
    map<char, int> mp;
    for (int i = 0; i < 52; i++) mp[Alpha[i]] = i;

    while (1) {
        cin >> n;
        if (n == 0) break;

        for (int i = 0; i < n; i++) cin >> k[i];
        cin >> s;

        for (int i = 0; i < s.size(); i++) {
            d = k[i % n];
            x = (mp[s[i]] + 52 - d) % l;
            cout << Alpha[x];
        }
        cout << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

typedef vector<vector<int> > graph;
vector<int> color;
graph G;

bool dfs(int s, int c) {
    color[s] = c;
    for (int i = 0; i < G[s].size(); i++) {
        int v = G[s][i];
        if (color[v] == c)
            return false;
        else if (color[v] == 0 && !dfs(v, -c))
            return false;
    }
    return true;
}

int main() {
    long long n, m;   cin >> n >> m;
    G = graph(n);
    color.resize(n);
    for (int i = 0; i < n; i++)
        color[i] = 0;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    if (dfs(0, 1)) {
        long long B = 0, W = 0;
        for (int i = 0; i < n; i++) {
            if (color[i] == 1)
                B++;
            else if (color[i] == -1)
                W++;

        }
        cout << B * W - m << endl;
    }
    else {
        cout << ((n*(n-1))/2) - m << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct Gragh {
    ll N;
    vector<vl> G;
    vl visited;

    Gragh(ll n) {
        N = n;
        G.resize(N);
        resetv();
    }

    void add(ll a, ll b) { G[a].push_back(b); }

    void resetv(void) { visited = vl(N, 0); }

    //重さ無し
    void dfs(ll x) {
        visited[x] = 1;
        for (ll i : G[x]) {
            if (visited[i] == 0) {
                dfs(i);
            }
        }
    }
};
int main() {
    cin >> n >> m;
    Gragh G(2 * n);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G.add(a * 2, b * 2 + 1);
        G.add(b * 2, a * 2 + 1);
        G.add(a * 2+1, b * 2);
        G.add(b * 2+1, a * 2);
    }

    G.dfs(0);
    vl dp(2, 0);
    rep(i, n * 2) {
        if (G.visited[i] == 1)dp[i % 2]++;
    }

    x=dp[0];
    y=dp[1];
    k=x+y-n;
    ans=k*(n-k)+k*(k-1)/2+(x-k)*(y-k)-m;

    cout << ans << endl;
}


#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll mod = 1000000007;
ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,r,ans;
long double a;
ll x[500005],y[500005];
bool flag,dame;

ll sa[40];
void solve(ll reside,ll a,ll b,bool first){
	//pe(reside);pe(a);p(b);
	if(a == 0){
		//p(reside);
		if(reside == 0){
			ans += b;
			//p(b);
		}
		return;
	}
	if(reside < -1 * 10 * a || 10 * a < reside)return;
	for(int i=-9;i<=9;i++){
		if((reside - i * a) % 10 == 0){
			if(a == 99){
				solve((reside - i * a)/10,a / 100,b * (sa[i + 10] - first) * 10,0);
			}else{
				solve((reside - i * a)/10,a / 100,b * (sa[i + 10] - first),0);
			}
		}
	}
}

int main(){
    cin >> n;
	num = 9;
	ans = 0;
	if(n % 9 != 0){
		p(0);return 0;
	}
	for(i=0;i<20;i++){
		sa[i] = 10 - abs(10 - i);
	}
	for(int i=0;i<18;i++){
		solve(n,num,1,1);
		//p(num);
		num *= 10;
		num += 9;
	}
	p(ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=4010,M=1000010,P=998244353;
const int inf=0x3f3f3f3f;
const int INF=0xcfcfcfcf;
const double eps=1e-6,pi=asin(1)*2;
inline ll read();
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
inline int ADD(int a,int b) { return a+b>=P?a+b-P:a+b; }
inline int MINUS(int a,int b) { return a-b<0?a-b+P:a-b; }
#define plus(a,b) a=ADD(a,b)
#define minus(a,b) a=MINUS(a,b)
#define mul(a,b) a=(a*(b))%P
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)

int K,n;
int C[N][N];
inline void init(int n=4000)
{
	for(int i=0;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=ADD(C[i-1][j-1],C[i-1][j]);
	}
}

const int sign[]={1,P-1};

#ifdef FILE
char buf[1<<25],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<25,stdin),p1==p2)?EOF:*p1++
#endif
inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^'0');
	if(flag) return -s;
	return s;
}

int main()
{
#ifdef FILE
	freopen(FILE ".in","r",stdin);
	freopen(FILE ".out","w",stdout);
#endif
	K=read(),n=read();
	init();
	for(int k=2;k<=2*K;k++)
	{
		int p=min(k/2,K-(k-1)/2);
		int ans=0;
		for(int i=0;i<=p;i++) plus(ans,1ll*sign[i&1]*C[p][i]%P*C[n-2*i+K-1][K-1]%P);
		printf("%d\n",ans);
	}
	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int kind[16];
	int unkind[16];

	for(int i=0; i<n; i++){
		int kind_p = 0;
		int unkind_p = 0;
		int t;
		cin>>t;
		while(t--){
			int a,b;
			cin>>a>>b;
			if(b) kind_p |=(1<<--a);
			else unkind_p|=(1<<--a);
		}
		kind[i] = kind_p;
		unkind[i] = unkind_p;
	}
	int maxpeople = 0;
	for(int i=0; i<(1<<n); i++){
		int totalkind = 0;
		int totalunkind = 0;
		for(int j=0; j<n; j++){
			if(i&(1<<j)){
				totalkind|=kind[j];
				totalunkind|=unkind[j];
			}
		}
		bool possible = true;
		for(int j=0; j<n; j++){
			if(totalkind&(1<<j) && (i&(1<<j))==0) possible = false;
			if(totalunkind&(1<<j) && i&(1<<j)) possible = false;
		}

		if(possible) maxpeople = max(maxpeople,__builtin_popcount(i));
	}
	//for(int i=0; i<n; i++) cout<<kind[i]<<" ";
	cout<<maxpeople;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int n;
  cin >> n;
  vector<vector<pair<int, int> > > data(n);
  for (int i = 0; i < n; i++) {
    int sz;
    cin >> sz;
    data[i].resize(sz);
    for (int j = 0; j < sz; j++) {
      cin >> data[i][j].first >> data[i][j].second;
      data[i][j].first--;
    }
  }
  int mask = (1 << n) - 1;
  while (mask) {
    int ppl = mask, i = n - 1;
    bool poss = true;
    while (ppl) {
      if (ppl & 1) {
        for (pair<int, int> p : data[i]) {
          int id = n - 1 - p.first;
          if (p.second && !((1 << id)&mask) || !p.second && (1 << id)&mask)
            poss = false;
        }
      }
      ppl /= 2;
      i--;
    }
    if (poss)
      break;
    mask--;
  }
  cout << __builtin_popcount(mask);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define rep(i, j) for(int i=0; i < (int)(j); i++)

using EdgeList = vector<vector<int>>;

// ?????£?????????????????°?????? E ????????£????????????????§£
// O(N + M) N: ????????°, M: ?????°
vector<vector<int>> strongly_connected_components(const EdgeList &E) {
    int N = E.size();
    vector<int> ord(N, -1), low(N);
    int cnt = 0;
    stack<int> stk;
    vector<bool> on_stack(N);
    vector<vector<int>> scc;
    function<void(int, int)> dfs = [&] (int now, int pre) {
        stk.push(now);
        on_stack[now] = true;
        ord[now] = cnt++;
        low[now] = ord[now];
        for(int nxt : E[now]) {
            if(ord[nxt] < 0) {
                // not visited
                dfs(nxt, now);
                low[now] = min(low[now], low[nxt]);
            } else if(on_stack[nxt]) {
                // visited
                low[now] = min(low[now], ord[nxt]);
            }
        }
        if(ord[now] == low[now]) {
            scc.push_back({});
            while(true) {
                int v = stk.top(); stk.pop();
                scc.back().push_back(v);
                on_stack[v] = false;
                if(v == now) break;
            }
        }
    };
    // ??£?????°????????????dfs(0)????????§OK?????????
    rep(i, N) if(ord[i] < 0) dfs(i, -1);
    return scc;
}

#define all(v) v.begin(),v.end()

struct UnionFind{
    int n;
    vector<int> p;
    UnionFind(int nn):n(nn) {
        p.resize(n);
        rep(i, n) p[i] = i;
    }
    int root(int x) {
        return p[x] == x ? x : (p[x] = root(p[x]));
    }
    void unite(int x,int y) {
        x = root(x); y = root(y);
        if(x != y) p[y] = x;
    }
    bool query(int x,int y){
        return root(x) == root(y);
    }
};

class Solver {
  public:
    bool solve() {
        int N, M; cin >> N >> M;
        EdgeList E(N);
        rep(i, M) {
            int a, b; cin >> a >> b;
            E[a].push_back(b);
        }
        auto scc = strongly_connected_components(E);

        UnionFind uf(N);
        for(auto &group : scc) for(int v : group) uf.unite(group.front(), v);

        int Q; cin >> Q;

        rep(i, Q) {
            int u, v; cin >> u >> v;
            cout << uf.query(u, v) << endl;
        }

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}

#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n = 0, m = 0;
vector<vector<int>> g;
vector<bool> vi;
vector<int> comp;
stack<int> post;
vector<pair<int, int>> q;
void input() {
    cin >> n >> m;
    g = vector<vector<int>>(n, vector<int>());
    vi = vector<bool>(n, false);
    comp = vector<int>(n, -1);
    q = vector<pair<int, int>>(0);
    while (m--) {
        int a = 0, b = 0;
        cin >> a >> b;
        g[a].push_back(b);
    }
    int Q = 0;
    cin >> Q;

    while (Q--) {
        int q1 = 0, q2 = 0;
        cin >> q1 >> q2;
        q.push_back({q1, q2});
    }
}

void dfs1(int i) {
    vi[i] = true;
    for (auto nig : g[i]) {
        if (vi[nig] == false) {
            dfs1(nig);
        }
    }
    post.push(i);
}
void reverseG() {
    vector<vector<int>> rev(n, vector<int>(0));
    for (int i = 0; i < g.size(); i++) {
        for (int j = 0; j < g[i].size(); j++) {
            int node = g[i][j];
            rev[node].push_back(i);
        }
    }
    g = rev;
}
void dfs2(int i, int comp_n) {
    comp[i] = comp_n;
    for (auto nig : g[i]) {
        if (comp[nig] == -1) {
            dfs2(nig, comp_n);
        }
    }
}
void compute() {
    for (int i = 0; i < n; i++) {
        if (vi[i] == false) dfs1(i);
    }
    reverseG();
    int comp_n = 0;
    while (!post.empty()) {
        int curr = post.top();
        post.pop();
        if (comp[curr] == -1) dfs2(curr, ++comp_n);
    }
    for (auto qq : q) {
        if (comp[qq.first] == comp[qq.second])
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
}

int main() {
    input();
    compute();
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

typedef pair<int,int> pii;
const int INF =  1000000000;

int par[10000],rnk[10000];

void init(int n){
  for(int i=0;i<n;i++){
    par[i] = i;
    rnk[i] = 1;
  }
}
int find(int x){
  if(par[x]==x) return x;
  else return par[x] = find(par[x]);
}
bool same(int x,int y){
  return find(x)==find(y);
}
void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(rnk[x]>rnk[y]) par[y] = x;
  else{
    par[x] = y;
    if(rnk[x]==rnk[y]) rnk[y]++;
  }
  return;
}

int main(){
  int V,E;
  vector<pair<int,pii> > es;
  scanf("%d %d",&V,&E);
  for(int i=0;i<E;i++){
    int s,t,w;
    scanf("%d %d %d",&s,&t,&w);
    es.push_back(make_pair(w,pii(s,t)));
  }
  int ans = 0;
  int cost[10000];
  fill(cost,cost+V,INF);
  sort(es.begin(),es.end());
  cost[0] = 0;
  init(V);
  for(int i=0;i<es.size();i++){
    if(!same(es[i].second.first,es[i].second.second)){
      ans += es[i].first;
      unite(es[i].second.first,es[i].second.second);
    }
  }
  printf("%d\n",ans);
  return 0;
}

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

struct Edge{
  int to,cost;
  bool operator<(const Edge&a)const{
    return cost>a.cost;
  }
};
struct Graph{
  Graph(int n):E(n),T(n),N(n){}
  vector<vector<Edge>>E,T;
  int N;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
    E[b].push_back({a,c});
  }
  void prim(int s){
    bool visited[N];
    priority_queue<pair<Edge,int>>Q;
    memset(visited,0,N);
    Q.push({{s,0},-1});
    while(Q.size()){
      Edge e=Q.top().first;
      int from=Q.top().second;Q.pop();
      if(visited[e.to])continue;
      visited[e.to]=1;
      if(from+1)T[from].push_back(e),T[e.to].push_back({from,e.cost});
      for(auto&a:E[e.to])
      if(!visited[a.to])Q.push({a,e.to});
    }
  }
  int get_cost(){
    int ret=0;
    for(auto&a:T)for(auto&b:a)ret+=b.cost;
    return ret/2;
  }
  vector<Edge>* get_MST(){
    return T.data();
  }
};

main(){
  int V,E,a,b,c;
  cin>>V>>E;
  Graph G(V);
  for(int i=0;i++<E;G.add_edge(a,b,c))cin>>a>>b>>c;
  G.prim(0);
  cout<<G.get_cost()<<endl;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から

typedef long long ll;

ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)

//cout<<fixed<<setprecision(10);
int main(){
    int p,q,r;
    cin>>p>>q>>r;
    cout<<p+q+r-max(p,max(q,r))<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r,a[3];
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    cout<<a[0]+a[1]<<"\n";
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
ll high_order_bit(ll n){
    ll tmp=1,i=-1;
    while(tmp<=n){
        tmp*=2;
        i++;
    }
    if(n==0) return 0;
    else return i;
}
vector<ll> binary_expansion(ll n){
    vector<ll> B(high_order_bit(n)+1);
    ll tmp=n;
    for(ll i=high_order_bit(n);i>=0;i--){
        B[i]=tmp/pw2[i];
        tmp%=pw2[i];
    }
    return B;
}
vector<ll> divisor(ll x){
    vector<ll> div;
    for(int i=1;i*i<=x;i++){
        if(i*i!=x && x%i==0){
            div.pb(i);
            div.pb(x/i);
        }
        else if(x%i==0) div.pb(i);
    }
    return div;
}
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}

int main(){
    {rep1(i,50) pw2[i]=(-2)*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}

    ll N,tmp; cin>>N;
    if(N==0){
        cout<<0;
        return 0;
    }
    tmp=N;
    vector<ll> ans;
    ll now=0; //0の位見てる
    while(tmp!=0){
        if(tmp%(pw2[now+1]) !=0 ){
            ans.pb(1ll);
            tmp -= pw2[now];
        }
        else{
            ans.pb(0ll);
        }
        now++;
    }
    rrep(i,sz(ans)) cout<<ans[i];
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0LL;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define IT ::iterator
#define F first
#define S second
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);

void solve()
{
    string v[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin >> s;
    int i;
    rep(i,7)
    {
        if(v[i]==s)
        {
            cout << 7-i ;
            break;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc=1;
   // cin >> tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}


//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
template <class T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
template <class T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int main(void) {
	string s; cin >> s;
	if (s.size() == 2)
		printf("%s", s.c_str());
	else
		for (int i = 2; i >= 0; i--)
			printf("%c", s[i]);
	printf("\n");

	return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <string>
using namespace std;
int main(){
    string s;
    while(cin>>s){
        if(s.length()==2){

        }else if(s.length()==3){
            reverse(s.begin(),s.end());
        }
        cout<<s<<endl;
    }

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//-------------------------------------------------------
int DP[301*301*301];
void Calc(){
	string S = res();
	int K = rei();
	int N = S.length();
	for(int i=0;i<N;i++){
		for(int j=N-1;j>i;j--){
			for(int k=0;k<=K;k++){
				DP[(i+1)*301*301+j*301+k] = max(DP[i*301*301+j*301+k],DP[(i+1)*301*301+(j+1)*301+k]);
				if(S[i] == S[j]){
					DP[(i+1)*301*301+j*301+k] = max(DP[(i+1)*301*301+j*301+k],DP[i*301*301+(j+1)*301+k]+1);
				}
				else if(k != 0){
					DP[(i+1)*301*301+j*301+k] = max(DP[(i+1)*301*301+j*301+k],DP[i*301*301+(j+1)*301+k-1]+1);
				}
			}
		}
	}
	int ans = 1;
	for(int k=0;k<=K;k++){
		for(int i=0;i<N-1;i++){
			ans = max(DP[(i+1)*301*301+(i+1)*301+k]*2,ans);
		}
		for(int i=0;i<N-2;i++){
			ans = max(DP[(i+1)*301*301+(i+2)*301+k]*2+1,ans);
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}