The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $$$n$$$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $$$m$$$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?Could you help her with this curiosity?You can see the examples and their descriptions with pictures in the "Note" section.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 1000$$$, $$$0 \leq m \leq n$$$) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.

Print a single integer — the maximum number of groups of cats at the moment Katie observes.

NoteIn the first example, originally there are $$$7$$$ cats sitting as shown below, creating a single group:  At the observed moment, $$$4$$$ cats have left the table. Suppose the cats $$$2$$$, $$$3$$$, $$$5$$$ and $$$7$$$ have left, then there are $$$3$$$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining.  In the second example, there are $$$6$$$ cats sitting as shown below:  At the observed moment, $$$2$$$ cats have left the table. Suppose the cats numbered $$$3$$$ and $$$6$$$ left, then there will be $$$2$$$ groups remaining ($$$\{1, 2\}$$$ and $$$\{4, 5\}$$$). It is impossible to have more than $$$2$$$ groups of cats remaining.  In the third example, no cats have left, so there is $$$1$$$ group consisting of all cats.In the fourth example, all cats have left the circle, so there are $$$0$$$ groups.

//#include <array>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
//#include <tuple>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
//#include<unordered_map>
//#include<unordered_set>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define fil(a,b) memset(a,b,sizeof(a))
#define fl(x,l,r) for(int x=l;x<r;x++)
#define fr(x,l,r) for(int x=l;x>r;x--)
//#define fcl(x,c) for(auto x=(c).begin();x!=(c).end();x++)
//#define fcr(x,c)for(auto x=(c).rbegin();x!=(c).rend();x++)
#define sc(x) scanf("%c",&x)
#define sd(x) scanf("%d",&x)
#define sf(x) scanf("%f",&x)
#define slf(x) scanf("%lf",&x)
#define sLf(x) scanf("%lf",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define pcn(x) printf("%c\n",x)
#define pdn(x) printf("%d\n",x)
#define pfn(x) printf("%f\n",x)
#define plldn(x) printf("%lld\n",x)
#define pd(x) printf("%d",x)
#define pc(x) printf("%c",x)
#define pf(x) printf("%f",x)
#define plld(x) printf("%lld",x)
#define ps(x) printf(x)
//#define psn(x) printf(x,"\n")
//#define pub(a,b) a.push_back(b)
//#define pob(a,b) a.pop_back(b)
//#define puf(a,b) a.push_front(b)
//#define pof(a,b) a.pop_front(b)
//#define pu(a,b) a.push(b)
//#define po(a) a.pop()
//#define lall(x) beg(x), end(x)
//#define rall(x) rbeg(x),rend(x)
//#define size(X) ((int)(X).size())
//#define sortcl(v) sort(lall)
//#define sortcr(v) sort(rall)
#define mp(x,y) make_pair(x,y)
//#define loc(v,x) lower_bound(lall,x)-beg(v)
#define pi 3.141592653589793
#define ui unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define blank printf("\n")
using namespace std;
const int inf1 = 0x3f3f3f3f;
const int inf2 = 0x7fffffff;
const int infd1 = 0x42424242;
const int infd2 = 0xc2c2c2c2;
const ll INF = ((ll)1) << 61;
typedef pair<int, int> twod;
typedef pair<double, double> twof;
typedef pair<char, char> twoc;
typedef pair<char, int> cd;
typedef pair<int, char> dc;
typedef pair<double, char> fc;
typedef pair<char, double> cf;
typedef pair<double, int> fd;
typedef pair<int, double> df;
//template<typename T> using min_q = priority_queue<T, vector<T>, greater<T>>;
inline int read() {
	char c = getchar(); int x = 0; bool sgn = false;
	while (c < '0' || c > '9') { if (c == '-') { sgn = true; } c = getchar(); }
	while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c & 15); c = getchar(); }
	return sgn ? -x : x;
}
const int maxn = 1e5 + 5;
const int maxe = 2e5 + 5;
int m, n;
int main() {
	//io;
	cin >> n >> m;
	if (m <= n / 2) {
		if (m == 0)
			cout << 1 << endl;
		else
			cout << m<<endl;
	}
	else {
		cout << n  - m << endl;
	}
	return 0;
}

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

const int MAXSIZE=1002;
int a[MAXSIZE];

int main()
{
    int n,m,flag;
    while(cin>>n>>m)
    {
        memset(a,0,sizeof(a));
        if(n%2)
        {
            a[0]=a[1]=1;
            for(int i=2;i<=(n/2);i++)
                a[i]=a[i-1]+1;
            a[n/2+1]=a[n/2];
            for(int i=(n/2)+2;i<=n;i++)
                a[i]=a[i-1]-1;
        }
        else
        {
            a[0]=a[1]=1;
            for(int i=2;i<=(n/2);i++)
                a[i]=a[i-1]+1;
            for(int i=(n/2)+1;i<=n;i++)
                a[i]=a[i-1]-1;
        }
        cout<<a[m]<<endl;
    }
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
   if(m==0)
    cout<<1;
   else
    cout<<min(m,n-m);
    return 0;
}

#include<cstdio>
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	if (n == m) printf("0");
	else if (m == 1 || m==0) printf("1");
	else {
		m--; n--;
		int ans = 0;
		while (m>0 && n>=2) {
			n -= 2; m--;
			ans++;
		}
		if (n > 0) ans++;
		while (m-- > 0) {
			if (n > 1) n--;
			else ans--;
		}
		printf("%d", ans);
	}
	return 0;
}

#pragma comment(linker, "/STACK:1000777216")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <cstring>
#include <bitset>
#include<ctime>
using namespace std;

using ll = long long;
using ld = long double;

const int MAXN = 1e5 + 10;

void precalc()
{

}

void solve()
{
	int n, m;
	cin >> n >> m;

	if (m * 2 <= n)
	{
		cout << max(1, m);
	}
	else
	{
		cout << n - m;
	}

	return;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(20);
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	precalc();
	solve();
#ifdef LOCAL
	cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}

// template version 1.9

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
const int INF=1e18;
const int MOD=1e9+7;
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int solve(){
  int n,m;cin>>n>>m;
  if (n==m) {
    cout << 0 << endl;
    return 0;
  }
  if (m==0) {
    cout << 1 << endl;
    return 0;
  }
  if (n==2 and m==1) {
    cout << 1 << endl;
    return 0;
  }
  cout << min(m, n-m) << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}

#include<bits/stdc++.h>

using namespace std;

/// Typedef
typedef long long ll;

#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)

#define pf1(a) printf("%lld\n", a)
#define pf2(a,b) printf("%lld %lld\n",a,b)

#define size1 105

int main() {

    ll tc, num, t = 1, choose;

    ll n, m;

    sc2(n, m);

    if(m == 1 || m == 0){
        return cout << "1" << endl, 0;
    }
    if(m == n){
        return cout << "0" << endl, 0;
    }

    ll ext = abs(n - m);

    if(ext + m == n)
      cout << min(ext, m) << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int vis[2500];
int main()
{

    int n,m;

    cin >>n>>m;

    if(n==m)
    {
          cout <<0<<endl;
          return 0;
    }
    else if(m==0)
    {
           cout <<1<<endl;
    }
    else
    {

      cout <<  min(m,n-m) <<endl;
    }

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,l,s=0;
    cin>>n>>m;
    l=n-m;
    if(n==m)
        s=0;
    else if(m<=1)
            s=1;
    else
    {
        if(2*l>=n)
        s=m;
    else
        s=l;
    }
    cout<<s<<endl;
}

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

int main()
{
    int n, m;
    cin >> n >> m;

    if (m==0  ||  m==1  ||  m==n-1)
    {
        cout << 1;
        return 0;
    }

    if (m==n)
    {
        cout << 0;
        return 0;
    }

    int dist;

    if (n%2==0  ||  (n%2!=0  &&  m<=n/2))
        dist=fabs(n/2-m);
    else
        dist=fabs((n/2+1)-m);

    cout << n/2-dist;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,m;
    cin>>n>>m;
    if(m==0)
    {
        cout<<1;
    }
    else if(n-m<=m)
    {
        cout<<n-m;
    }
    else if(n-m>m&&m!=0)
    {
        cout<<m;
    }
    return 0;
}

#include <iostream>
using namespace std;

int main()
{
    int n = 0, m = 0, result = 0;
    cin >> n >> m;
    if(!m)
    {
        cout << 1;
    }
    else if(m <= n / 2)
    {
        cout << m;
    }
    else
    {
        cout << n-m;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if(m <= n - m && m != 0)
    {
        cout << m;
    }
    if(m > n - m)
    {
        cout << n - m;
    }
    if(m == 0)
    {
        cout << 1;
    }
    return 0;
}

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

int main(){
    int n,m; cin>>n>>m;
    if(m==0){
        cout<<1<<endl;
    }
    else{
        cout<<min(m,n-m)<<endl;
    }
    return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    if(m==0)
    {
        cout<<1<<endl;
        return 0;
    }
    if(n%2==0)
    {
        int x=n/2;
        if(m<=x)
        {
            cout<<m<<endl;
        }
        else
        {
            cout<<n-m<<endl;
        }
    }
    else
    {
        int x=(n-1)/2;
        if(m<=x)
        {
            cout<<m<<endl;
        }
        else
        {
            cout<<n-m<<endl;
        }

    }

    return 0;
}

#include <bits/stdc++.h>
#include <cstring>
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
    {
sim > struct rge
{
    c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(std::cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
    ~debug()
    {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c &)
    {
        ris;
    }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const long long INF = 1e18L + 5; // 10^18
#define fastIN  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    fastIN
    //freopen("input.in", "r", stdin);
    ll  a,b;

    cin>>a>>b;
    if(b==0)
    cout<<1;
    else{
        ll x=min(a-b,b);
        cout<<x;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
long long mod = 1000000000+7;
  long long  pow(long long  a, long long  b, long long m)
 {
        stack<int>k;
        int j = 128;
        int l = 1;
       int an = 1;
        while(b){
            if(b>=j){
                k.push(j);
                b-=j;
            }
            j/=2;
        }
        while(!k.empty()){
            if(k.top()==l){
                an = (an*a)%mod;
                k.pop();
            }
            a = (a*a)%mod;
            l*=2;
        }

        return an;
 }
    long long smallest (int x,int y){
    x--;
    long long o = 1;
    long long re = 0;
    while(1){
        if(x){
            re += o;
            x--;
        }
        else if (y){
            y--;
        }
        else{
            break;
        }

        o*=2;
    }
    re += o;
    return re;
    }
   long long biggest (int x,int y){
    x--;
    long long o = 1;
    long long re = 0;
    while(1){
        if(y){
            y--;
        }
        else if (x){
                re +=o;
            x--;
        }
        else{
            break;
        }

        o*=2;
    }
    re += o;
    return re;
    }
    int x[42] = {0};
 int main(){
    ios_base::sync_with_stdio(0);cin.tie(NULL);
   int n ,m,g=1;;
   cin>>n>>m;

   n--,m--;
   stack<int>st,st1,st2;
   st.push(n);
   for(int i = 0;i<m;++i){
    //        cout<<st.size()<<endl;
    if(!st.empty()){
        int u = st.top();
  //  cout<<u<<endl;
        st.pop();
        g--;
        int s ,s1;

        if(u%2==0){
            s = u/2;
            s1 = u/2;
            s1--;
        }
        else{
            s = u/2;
            s1 = s;
        }
        //cout<<s<<endl;
        if(s==1){
            st1.push(s);
            g++;

        }
        else if(s==2){st2.push(2);g++;}
        else if(s!=0)  {
            st.push(s);
            g++;
        }
        if(s1==1){
            st1.push(s1);
            g++;
        }
         else if(s1==2){st2.push(2);g++;}
        else if(s1!=0)   {
            st.push(s1);
            g++;
        }
    }
    else if (!st2.empty()){
      //      cout<<1<<endl;
        if(st2.size()>1){
         g++;
         st1.push(1);
         st1.push(1);
         st2.pop();
         st2.pop();
        }
        else {
            st2.pop();
            st1.push(1);
        }
    }
    else  {
        st1.pop();
        g--;
    }
       // cout<<g<<endl;
   }
   cout<<g<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mem(a, x) memset(a, x, sizeof a)
//#define int long long

using namespace std;
typedef long long ll;

template <typename _T>
void read(_T &x) {
    int f = 1; x = 0;
    char s = getchar();
    while (s > '9' || s < '0') {if (s == '-') f = -1; s = getchar();}
    while (s >= '0' && s <= '9') x = (x<<3)+(x<<1)+(s-'0'), s = getchar();
    x *= f;
}

int main() {
    int n, m; read(n); read(m);
    if (m == 0) puts("1");
    else if (m <= n/2) printf("%d", m);
    else printf("%d", n-m);
    return 0;
}

#include<iostream>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    int ans=0;
    if(m<=1){
       ans=1;
    }else{
        ans=min(m,n-m);
    }
    cout<<ans<<endl;
return 0;
}

#include<iostream>

using namespace std;

int findSth(int n, int m) {
	if (m == n)
		return 0;
	if (m == n - 1)
		return 1;
	if (m == 0)
		return 1;
	int res = 0;
	if (m % 2 != 0) {//so le
		if (m >= 1 && m <= (n - 1) / 2)
			res = m;
		else if (m > (n - 1) / 2) {
			m = n - m;
			res = m;
		}
	}
	else {
		if (m >= 1 && m <= n / 2)
			res = m;
		else if (m > n / 2) {
			m = n - m;
			res = m;
		}
	}
	return res;
}

int main() {
	int n, m;
	cin >> n >> m;
	cout << findSth(n, m);

	//system("pause");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    if(m==0){
    	cout<<1;
		return 0;
	}else{
		if(n-m<n/2){
			if(m<n-m){
				cout<<m;
				return 0;
			}else if(n-m<m){
				cout<<n-m;
				return 0;
			}
		}else if(n/2<n-m){
			if(m<n/2){
				cout<<m;
				return 0;
			}else if(n/2<m){
				cout<<n/2;
				return 0;
			}
		}
	}
    cout<<min(m,min(n-m,n/2))<<endl;
}

#include <iostream>

using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    if(n == 0) cout << "0";
    else if(m == 0) cout << "1";
    else if(m == n) cout << "0";
    else {
        int ans = 0;
        m = n - m;
        while(n > m && m) ++ans, n -= 2, --m;
        if(m > n) --ans;
        cout << ans;
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;

	int ar[n] = {0};
	int pos = 0;
	int temp=m;

	if(m==0)
	{cout<<1; return 0;}

	for(int i=0;i<n;i+=2)
	{ar[i] = 1;		--m;	if(m==0) break;}

	//cout<<"m="<<m;
	pos = 1;
	for(int i=1;i<=m;++i)
		{ar[pos] = 1;	pos+=2;	}

	int count=0;

	for(int i=0;i<n;++i)
	{
		//cout<<ar[i]<<" ";
		if(ar[i]==0 && ar[i-1]==1)
			count++;
	}
	cout<<count<<endl;
}

#include<iostream>
using namespace std;
int main(){

	int n;cin>>n;
	int m;cin>>m;

    if(m==0)cout<<1;
	else if(n==m)cout<<0;
	else if(m*2<=n)cout<<m;
	else if(m*2>n)cout<<n-m;

return 0;}

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

int main()
{
		int n,m;
		cin>>n>>m;

		if(m==0)
		{
			cout<<1<<endl;
			//continue;
		}

		else if(m>(n/2))
		{
			if(n%2==0)
			{
				int ans=n/2;
				m=m-(n/2);

				while(m--)
				ans--;

				cout<<ans<<endl;
				//continue;
			}

			else
			{

				int ans=n/2;
				m=m-(n/2);
				--m;

				while(m--)
				ans--;

				cout<<ans<<endl;
				//continue;

			}
		}

		else
		cout<<m<<endl;

	return 0;
}

//A
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	if(n>=m*2){
		if(m==0)m=1;
		printf("%d\n",m);
	}else if(n<=m){
		printf("0\n");
	}else {
		int ans = n/2-(m-n/2);
		if(n%2==1)ans+=1;
		printf("%d\n",ans);
	}
	return 0 ;
 }

#include<iostream>
using namespace std;
int main()
{
	int m, n, r;
	cin >> n >> m;
	if (m == 0)	r = 1;
	else if (n >= 2 * m)
		r = m;
	else
		r = n - m;
	cout << r << endl;
	return 0;
}

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

#define ll long long int
#define mod 1000000007
#define pb push_back
#define pop pop_back
#define mp make_pair
#define ALL(v)  v.begin(), v.end()

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    if(m == 0) {
        cout << 1;
        return 0;
    }
    if(m <= n / 2)
        cout << m;
    else
        cout << n - m;
    return 0;
}

#include <iostream>
using namespace std;

int main() {
int a,b;
cin>>a>>b;
if(a==b)
{cout<<0<<endl;
return 0;
}
cout<<max(1,min(b,a-b))<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,x,n,m,l;
    cin>>n>>m;
    if(m==0||m==1)
    {
        x=1;
    }
    else if(n==m)
    {
        x=0;
    }
    else
    {
        if(n/m>1)
        {
            x=m;
        }
        else
        {
            x=n-m;

        }
    }
    cout<<x<<endl;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;

	int ar[n] = {0};
	int pos;
	int grps = n/2;

	if(n==m)
	{cout<<0;	return 0;}

	if(m==0 || m==1)
	{cout<<1;	return 0;}

	if(n%2!=0 && m>n/2)
		--m;
	if(m>grps)
		pos = grps - (m%grps);
	else
		pos = m;

	cout<<pos<<"\n";

}

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

int main()
{
    int n,m,d;
    cin>>n>>m;
    if(n==m)cout<<0<<endl;
    else if(m==0||m==1)cout<<1<<endl;
    else if(n%2!=0){
            d=n/2;
            cout<<min(d,min(n-m,m));
        }

      else if(n%2==0){
            d=n/2;
            cout<<min(d,min(n-m,m));
        }

}

#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	cout << (m==0?1:min(n - m, m));
	return 0;
}

///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].fe << " " << v[i].se << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void PP(int n) { cout << n << " ";}
inline void PP(int n, int m) { cout << n << " " << m << endl;}
inline void PP(int n, int m, int q) {  cout << n << " " << m << " " << q << endl;}
inline void PP(int n, int m, int q, int u) {  cout << n << " " << m << " " << q << " " << u << endl;}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <=================================================================================================================================
// <=================================================================================================================================

signed  main() {
    op();
    lets_go
    int i, j, x, y, u, l;
    // int tt; cin >> tt; while (tt--)
    {
        i = j = x = y = u = l = 0;

        cin >> x >> y;
        l = x - y;
        if (l == 0) {
            PT(0);
        }
        else if (y == 0 || y == 1) {
            PT(1);
        }
        else {
            if (y > x / 2) {
                PT(l);
            }
            else
                PT(y);
        }

        /* */
    }
    return 0;

}

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define y second
#define x first

using namespace std;
typedef long long INT;
typedef pair<int, int> pii;
template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}
typedef vector<int> VI;

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, k; scanf("%d %d", &n, &k);
	int a=n+1>>1, b=n-a;
	if(!k) puts("1");
	else if(k<a) cout<<k;
	else cout<<n-k;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
if(m==1||m==0)
    cout<<1<<endl;
else if(m==n)
    cout<<0<<endl;
else {
        m=n-m;
        if(n%2){
        if(m<=n/2)
        cout<<m<<endl;
else
    cout<<n/2-(m-n/2-1)<<endl;
}
else{
    if(m<=n/2)
        cout<<m<<endl;
    else
        cout<<n/2-(m-n/2)<<endl;
}
}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define sz(x) ((int)((x).size()))
#define ll long long
#define F first
#define S second
typedef pair <int , int > PI;
map < ll , ll > mp ;
map < ll , ll > mp1 ;
ll t[1000000];
int prime(int x ){
    if(x == 1 ) return 0;
    for(int i  = 2 ; i <= sqrt(x) ; i++){
        if(x%i == 0)
            return 0;
    }
    return 1 ;
}
int powr (int x , int y  ){
    if(y==0) return 1 ;
    return x*powr(x,y-1);
}
int m1 [1000][1000];
int m2 [1000][1000];
PI p[1000000];
int main  (){        io;

   ll n  , m  , res  ;
   cin >> n >> m ;
   if( m == 0 ) { cout<<1; return 0 ;  }
   res =  n / 2 ;
   if( m <= res   ) cout<< m   ;
  else {
        if ( n & 1 ) m--;
        cout << res - (m  -  res  );
  }

      return 0;
}

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,m;
	cin>>n>>m;
	if(n==m)
		cout<<"0";
	else if(m==0||m==1)
		cout<<"1";
	else if(n%m==0)
		cout<<m;
	else if ((n-m)>(n%m))
		cout<<m;
	else
		cout<<n%m;

	return 0;
}

//#include<bits/stdc++.h>

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<vector>
#include<string>
#include<cmath>
#include<map>
// 防止UKE
using namespace std;
// 防止UKE
int main()
{
    int n,m;
    cin>>n>>m;
    if(m==0)
        cout<<1;
    else
        cout<<min(m,min(n-m,n/2))<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
	cin>>n>>m;
	cout<<min(n-m,max(1,m));
}

#include<bits/stdc++.h>
using namespace std;
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define pb push_back
#define int long long
#define hii cout << "hii" << endl
#define si size()
#define ff first
#define ss second
#define all(s) s.begin(), s.end()

const int N = 5e5 + 5;

int arr[N];

int n, k;

int32_t main()
{
    cin >> n >> k;
    FOR(i, 0, n) cin >> arr[i];

    if(k == 0)
    {
        cout << 1;
        return 0;
    }

    if(n & 1)
    {
        if(n/2 >= k)
        {
            cout << k << endl;
        }
        else
        {
            k -= n/2;
            k -= 1;

            cout << n/2 - k;

        }
    }
    else
    {
        if(n/2 >= k)
        {
            cout << k;
        }
        else
        {
            k -= n/2;
            cout << n/2 - k;
        }
    }
}

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

int main()
{
    int n,m;
    cin>>n>>m;

    if(!m)
        return cout<<1<<endl, 0;

    int hh= (n+1)/2;
    int baki= n-hh;
    int shesh= min( m, baki );
    int thaklo= m-shesh;
    int ans= shesh-thaklo;

    if(baki<m and n&1 )
        ans++;

    cout<< ans <<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c=0,c1=0,i;
    cin>>n>>m;
    if(m>=n)
    cout<<"0";
    else if(m==0 || m==1)
    cout<<"1";
    else
    {
        cout<<min(m,n-m);
    }
}

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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;

	if (n == m)
		cout << 0 << endl;
	else if (m == 0)
		cout << 1 << endl;
	else if ((n - m) >= m)
		cout << m << endl;
	else
		cout << n - m << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sys system("pause")
#define scan(n) scanf("%I64d", &(n))
#define scann(n, m) scanf("%I64d%I64d", &(n), &(m))
#define prin(n) printf("%I64d", (n))
#define scannn(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define ms(a) memset(a, 0, sizeof(a))
#define prinspace printf("\n")
#define fo(i, a, b) for (int i = (a); i <= (b); i++)
#define ro(i, a, b) for (int i = (a); i >= (b); i--)
#define guagua1
#ifdef guagua
    #define dbg(args...) do {cout << #args << " : "; err(args);} while (0)
#else
    #define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
const int maxn = 2e5 + 100;
const int inf = 0x3f3f3f3f;
int a[maxn];
int32_t main(){
    int n,m;scann(n,m);
    int ans=0;
    if(m==0){printf("1");return 0;}
    int t=n/2;
    if(m>t){
        if(n&1)m--;
        ans=t;
        m-=t;
        while(m>0){
            m--,ans--;
        }
    }
    else ans=m;
    prin(ans);
#ifdef guagua
    sys;
#endif

	return 0;
}

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main(){

          int n,m,c = 1,k=0,d = 0;
          cin >> n >> m;
          int a[n],b[n];

        k = n/2;

          if(n == m)
          cout << 0;

          else if(m == 0 || (n-m) == 1)
          cout << 1;

          else if(m > k)
            cout << (n-m);

          else{
            for(int i =0 ;i<n;i++){
            a[i] = i+1;
            b[i] = i+1;
            }

          for(int j =1;j<=m;j++)
            a[2*j - 1] = 0;

            for(int j =0;j<m;j++)
              b[2*j] = 0;

          for(int j = 0;j<n;j++)
          {
            if(a[j] == 0)
            c++;
          }
          for(int j = 0;j<n;j++)
          {
            if(b[j] == 0)
            d++;
          }
            if(d > c)
            cout << c;

            else
            cout << d;

        }
}

//Written by Rhitwik Saha//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MAX 4000100
#define M 998244353
#define int long long
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define rrep(i,a,b) for(int(i)=(a);(i)>=(b);i--)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pr(a) printf("%d ",a)
#define vi vector< int >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

int i,j,k;

void solve(){
	int n,m;
	cin>>n>>m;
	if(m==0){
		cout<<1;
		return;
	}
	if(m-1>=n/2)cout<<n-m;
	else cout<<m;
}
int32_t main(){
	fastio;
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}

}

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define reset(N) memset(N,0,sizeof(N))
#define clear(N) while(N.size()>0) N.pop()
#define f(a,v,b) for(int a=v;a<b;a++)
#define cb(N) __builtin_popcount(N)
#define cbl(N) __builtin_popcountl(N)
#define cbll(N) __builtin_popcountll(N)
using namespace std;
int x,y;
void solve(){
	cin>>x>>y;
	if(y==0){
		cout<<"1\n";
		return;
	}
	cout<<min(y,x-y)<<'\n';
}
int main(){
	ios::sync_with_stdio(false);
	solve();
}

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>

#include <algorithm>
#include <queue>
#include <functional>
#include <stack>
#include <vector>
#include <tuple>
#include <iostream>
#include <map>
#include <string>
#include <deque>
#include <set>

using namespace std;

using lint = long long;

using ii = pair < int, int >;
using ll = pair < lint, lint >;
using ti = tuple < int, int, int >;
using il = pair < int, lint >;

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define sc(x) scanf("%d", &x)
#define pf(x) printf("%d",x)
#define ps() puts("")
#define fo(i,n) for(int i=0;i<n;i++)

const int N = 1e6 + 5;
const int M = 1e2 + 5;
int n, m, k;
char s[N];
int a[N], b[N];

void input() {
	sc(n);
	sc(m);
	if (m == 0) {
		puts("1");
	}
	else if (m < n % 2 + n / 2) {
		printf("%d\n", m);
	}
	else {
		printf("%d\n", n - m);
	}
}

void go() {

}

#define D

int main() {
#ifdef Da
	freopen("in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	input();
	go();
}

// need
#include <fstream>
#include <iostream>
#include <algorithm>
// other
#include <cmath>
#include <vector>
#include <numeric>
#include <cstring>

using namespace std;

#define MP make_pair
#define PB push_back
#define FI first
#define SE second

#define ALL(c) (c).begin(), (c).end()
#define REP(i,a,b) for (int i = a; i < b; i++)

typedef long long ll;
typedef long double ld;

int main(void) {
	int n, m; cin >> n >> m;
	if (n / 2 >= m) cout << max(m, 1);
	else cout << n - m;
}

#include<bits/stdc++.h>
using namespace std;
int vis[2500];
int main()
{

    int n,m;

    cin >>n>>m;

    if(n==m)
    {
          cout <<0<<endl;
          return 0;
    }
    else if(m==0)
    {
           cout <<1<<endl;
    }
    else
    {

      cout <<  min(m,n-m) <<endl;
    }

}

#include <iostream>
#include <bits/stdc++.h>
#include <string.h>

using namespace std;

int main()
{
  int n,m;
  cin>>n>>m;
  if (n==m)
    cout<<0;
  else if (m==0 || m==1)
    cout<<1;
  else if( (n%2!=0 ||  n%2==0) && m<=(n/2)  )

  cout<<m;

  else if ((n%2==0 || n%2!=0) && m>n/2)
  {
      cout<<n-m;
  }

return 0;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define pii                pair < int , int >
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define vecsum(v)          accumulate(v.begin(), v.end(), 0)
#define adj_diff(a,b)      adjacent_difference(a.begin(), a.end(), b.begin())
#define IOTA(a,x)          iota(a.begin(), a.end(), x);
#define par_sum(a,sum)     partial_sum(a,a+sizeof(a),sum)
#define fast_cin           ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()
{

     int n , m ;
     cin >> n >> m ;
     if( m == 0 ){
        cout << 1 << endl;
        return 0;
     }
     cout << min(m,n-m) << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
//typedef long long ll;
typedef  long long ll;
#define vt vector
#define all(v)  v.begin(),v.end()
typedef vt<long long> vii;
const ll M=998244353;
  int main()
{
 /*ll t;
 cin>>t;
 while(t-->0)
 {*/
 ll n,k;
 cin>>n>>k;
 if(k==0)
 {
     cout<<1;
     return 0;
 }
 if(k<ceil((double)n/2))
    cout<<k<<endl;
 else
    cout<<n-k;
 //}
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define r0 return 0
#define INF 9e+18
#define ll long long int
#define br cout<<"\n"
#define vll vector<ll>
#define pb push_back
#define MOD 1000000007
#define vsort(v) sort(v.begin(),v.end())
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())

void addwedge(vector <pair<ll, ll> > adj[], ll u, ll v, ll wt)
{
    adj[u].pb(make_pair(v, wt));
    adj[v].pb(make_pair(u, wt));
}
void addedge(vector<ll>adj[],ll u,ll v)
{
    adj[u].pb(v);
    adj[v].pb(u);
}

  vector<ll> shortestpath(vector<pair<ll,ll> > adj[], ll V, ll src)
{
    priority_queue< pair<ll,ll>, vector <pair<ll,ll>> , greater<pair<ll,ll>> > pq;
    vector<ll> dist(V, INF);

    pq.push(make_pair(0, src));
    dist[src] = 0;

    while (!pq.empty())
    {
        ll u = pq.top().second;
        pq.pop();

        for (auto x : adj[u])
        {
            ll v = x.first;
            ll weight = x.second;

            if (dist[v] > dist[u] + weight)
            {
                dist[v] = dist[u] + weight;
                pq.push(make_pair(dist[v], v));
            }
        }
    }
 return dist;
}

void buildsegment( ll arr[],ll tree[],ll n)
{

	for (ll i=0; i<n; i++)
		tree[n+i] = arr[i];

	for (ll i = n - 1; i > 0; --i)
		tree[i] = tree[i<<1] + tree[i<<1 | 1];
}

void updatesegment(ll p, ll value, ll tree[],ll n)
{

	tree[p+n] = value;
	p = p+n;

	for (ll i=p; i > 1; i >>= 1)
		tree[i>>1] = tree[i] + tree[i^1];
}

ll querysegment(ll l, ll r,ll tree[],ll n)
{
	ll res = 0;

	for (l += n, r += n; l < r; l >>= 1, r >>= 1)
	{
		if (l&1)
			res += tree[l++];

		if (r&1)
			res += tree[--r];
	}

	return res;
}

long long int findpar(long long int numb,long long int par[])
{
    if(par[numb]==numb )return numb;
    else return par[numb]=findpar(par[numb],par);
}
void setpar(long long int u1,long long int v1,long long int par[])
{
    long long int s1=findpar(v1,par);
    long long int s2=findpar(u1,par);
    if(s1<s2){par[s2]=s1;}
    else {par[s1]=s2;}

}
ll extended_GCD(ll a , ll b , ll &x , ll &y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b % a , a , x1 , y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return gcd;
}

ll modinv(ll a , ll mod = MOD) {
    ll x , y;
    extended_GCD(a , mod , x , y);
    if (x < 0) x += mod;
    return x;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return ans;
}
vll nge(ll arr[], ll n) {
  stack <ll> s;
  vll ans(n,-1);
  s.push(0);

  for (ll i = 1; i < n; i++) {

    if (s.empty()) {
      s.push(i);
      continue;
    }

    while (s.empty() == false && arr[s.top()] < arr[i])
    {
        ans[s.top()]=i;
        s.pop();
    }

    s.push(arr[i]);
  }

  return ans;
}
void swap(ll& a,ll& b)
{
    ll temp=a;
    a=b;b=temp;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t=1,n,m;
//	cin>>t;
	while(t--)
	{   cin>>n>>m;
	if(m==0){cout<<1<<endl;r0;}
else m-=1;
n-=1;
if(n%2==1)
{
    if(m<=n/2)cout<<m+1<<endl;
    else cout<<((n/2)+1)-(m-n/2)<<endl;
}
else
{
    if(m<=n/2)
    {
        if(m!=n/2)
        cout<<m+1<<endl;
        else cout<<n/2;
    }
    else cout<<(n/2)-(m-(n/2))<<endl;
}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    if(m==0){
    	cout<<1;
		return 0;
	}else{
		cout<<min(m,min(n-m,n/2))<<endl;
	}
}

#include<iostream>
using namespace std;
int main(){
	int n, m, middle;
	while(cin >> n >> m){
		middle = n / 2;
		//cout << "middle  "<< middle << endl;
		if(m == 0){
			cout << 1 << endl;
		} else if(m == n){
			cout << 0 << endl;
		} else{
			if(m <= middle){   // 前半段
				cout << m << endl;
			} else{			  //后半段
				if(n%2 == 0){   //偶数
					cout << n - m << endl;
				} else{         //奇数
					cout << n - m << endl;
				}
			}
		}
	}
}

//==================================================================================================
// Name        : Autori.cpp
// Author      : lotus.eater086
// Copyright   : If you're reading this then this warning is for you. Every word you read of this
//               useless fine print is another second of your life. Don't you've other things to do?
//               Is your life so empty that you honestly can't think of a better way to spend these
//               moments ? Or are you so impressed with authority that you give respect and
//               credence to all who claim it ? Do you read everything you're supposed to read ? Do
//               you think everything you're supposed to think ? Buy what you're told you should
//               want ? Get out of your apartment . Meet a member of the opposite sex. Stop the
//               excessive shopping and self-improvement . Quit your boring job.
//               Start a fight. Prove you're alive. If you don't claim your humanity you'll become a
//               statistic. You've been warned !

// Description :
// Date        : 2019-05-09 , Thursday
// Time        : 21:04:50
// Directory   : e:\Practise\VS_Code\stl_practise_code
// FilePath    : e:\Practise\VS_Code\stl_practise_code\Autori.cpp
//==================================================================================================

#include <bits/stdc++.h>
#define LL long long
#define endl "\n"

using namespace std ;

//
template < typename T >

inline T read( T &x )
{

    x = 0 ;

    int f = 0 ;

    char ch = getchar() ;

    while( ch < '0' || ch > '9' )  {

        f |= ( ch == '-' ) , ch = getchar() ;

    }

    while( ch >= '0' && ch <= '9' )  {

        x = ( x << 1 ) + ( x << 3 ) + ch - '0' , ch = getchar() ;

    }

    return x = f ? -x:x ;

}
//

int main( void )

{

    //ios_base::sync_with_stdio( false ) ;  cin.tie( NULL ) ;  cout.tie( NULL ) ;

    #ifndef ONLINE_JUDGE
        freopen( "input.txt" , "r" , stdin ) ;
        freopen( "output.txt" , "w" , stdout ) ;
    #endif

    double n , m ;

    cin >> n >> m ;

    if(m==0)  cout << 1 << '\n' ;

  else  if( m < n/2.0 )  cout << m << endl ;

    else cout << (n-m) << endl ;

    #ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << " sec\n" ;
    #endif
     // ?
    return 0 ;

}

#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(m==0){
		cout<<"1"<<endl;
		return 0;
	}

	else if(m==n){
		cout<<"0"<<endl;
		return 0;
	}

	int num,flag=0;
	if((n&1)!=0)
		flag=1;
	int t=n/2;
	if(m<=t)
		cout<<m<<endl;
	else{
		if(flag==0)
			cout<<t-(m-t)<<endl;
		else
			cout<<t-(m-t-1)<<endl;
	}
	return 0;
}

#include<stdio.h>
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	if(m==0){
		printf("1");
		return 0;
	}
	if(n%2==0){
		if(n/2>=m)
			printf("%d",m);
		else
			printf("%d",n-m);
	}
	else {
		if((n/2)>=m)
			printf("%d",m);
		else if((n/2)==m)
			printf("%d",m-1);
		else
			printf("%d",n-m);
	}
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;

int n,m;

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int x=n-m;
        int ans = min(x,m);
        if(m==0)
            ans=1;
        printf("%d\n",ans);
    }

    return 0;
}

#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(m==0)
	{
		cout<<1<<endl;
		return 0;
	}
	if(n==m)
	{
		cout<<0<<endl;
		return 0;
	}
	cout<<min(m,n-m)<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,m;

int main()
{
	int n,m;
	cin>>n>>m;
	if(m==0){
		cout<<1;
		return 0;
	}
if(m>n/2){
	cout<<n/2-(m-n/2)+n%2;
	return 0;
}
if(m<n/2){
	cout<<m;
	return 0;
}
if(m==n/2){
	cout<<n/2;
}

return 0;
}

#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define rep(a,n,b) for(long int i=a;i<n;i+=b)
#define pb(i) push_back(i)
#define ll long long int
#define PI 3.1415926535
#define INTMAX 100000000000000000
#define mod 10000000007
#define input freopen("input.txt","r",stdin)
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
int main() {
  // input;
  fastio;
  int n,m,ans=0;
  cin>>n>>m;
  int arr[n+1];
  fill(arr,arr+n+1,1);
  rep(1,n+1,2) {
    if(m==0) break;
    arr[i] = 0;
    m--;
  } if(m)  {
    rep(2,n+1,2)  {
      if(m==0) break;
      arr[i] =0;
      m--;
    }
  }
  rep(1,n+1,1) {
    if(arr[i]) {
      while(arr[i]) i++;
      ans++;
    }
  }
  cout<<ans;
}

/*
 * https://codeforces.com/problemset/problem/1163/A

 The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...

What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends.
Now n cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.

Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided
into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are m cats who left the circle.
This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?

Could you help her with this curiosity?

Input

The only line contains two integers n and m (2≤n≤1000, 0≤m≤n) — the initial number of cats at the party and the number of cats who left the circle
at the moment Katie observes, respectively.

Output

Print a single integer — the maximum number of groups of cats at the moment Katie observes.

SAMPLE:
7 4
	3

6 2
	2

3 0
	1

2 2
	0

Troublesome Inputs:
729 501
	228

Observations:
	- A group is defined as a vertex of degree x and all its connected nodes, even if x = 0
	- How can you remove m vertices to leave the maximum number of groups?
	- Case n == m
		- Return 0, as no cats are left
	- Case m == 0, m == 1, or n-m == 1
		- Return 1, as all components still connected
	- Case n = 2k+1
		- Ex n = 7
			- m = 0 or m = 1, answer is 1
			- m = 2, answer is 2
			- m = 3, answer is 3
			- m = 4, answer is 3
			- m = 5, answer is 2
			- m = 6, answer is 1
		- Subcases m = 2b+1 or m=2b+2 are equal

	- Case n = 2k
		- Ex n = 6
			- m = 0 or m = 1, answer is 1
			- m = 2, answer is 2
			- m = 3, answer is 3
			- m = 4, answer is 2
			- m = 5, answer is 1
	- for n/2 >= m >= 2
		- return (n/2)-((n/2)-m)
	- for n-1 >= m > n/2
		- return (n/2)-(m-(n/2))
 */
#include <iostream>

template<typename T>
void print(T t) { std::cout << t << std::endl; }

int main()
{
	int n, m;
	std::cin >> n >> m;

	// Case 0, 1, n-1
	if (m == 0)						{ print(1); return 0; }
	// Case m == n
	if (m == n)						{ print(0); return 0; }
	// 2 | n
	if 		(n%2==0 && m < (n/2))	{ print(m); return 0; }
	else if (n%2==0 && m >= (n/2))	{ print(n-m); return 0; }
	// ~ 2 | n
	if 		(m <= (n/2))			{ print(m); return 0; }
	else							{ print(n-m); return 0; }

	return 0;
}

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

int main(){
    int n,c;
    cin >> n >> c;

    if(c == 0)
        cout << 1 << endl;
    else if(c <= n/2)
        cout << c << endl;
    else
        cout << n%c << endl;
}

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = INT_MAX;

//const double PI = acos(-1);

int main() {

    int n, m;
    cin >> n >> m;
    if (m == n) {
        cout << 0;
        return 0;
    }
    if (m < 2 || n <= 2) {
        cout << 1;
        return 0;
    }
    m--;
    n--;
    int ans = 1;
    while (n > 2 && m > 0) {
        ans++;
        m--;
        n -= 2;
    }
    if (m > 0) {
        if (n == 2) {
            m--;
        }
        ans -= m;
    }
    cout << ans;
}

#include <iostream>
#include <bits/stdc++.h>
#define LL long long
#define Clear(a,x) memset(a,x,sizeof(a))
using namespace std;

int main()
{
    LL n, m;
    cin >> n >> m;
    if(m == 0) cout << 1 << endl;
    else{
        LL ans = n/2 - abs(m - (n + 1)/2);
        if((n & 1) &&m < (n + 1)/2){
            ans ++;
        }
        cout << ans << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define ll long long int
#define db double
#define SORTA(v) sort(v.begin(),v.end())
#define SORTD(v) sort(v.begin(),v.end(),greater<>())
#define endl '\n'
#define nod(N) floor(log10(N)) + 1
#define LB(a) lower_bound(a)
#define UB(a) upper_bound(a)
#define F first
#define S second
#define FOR(i,n) for(long long int i = 0;i<n;i++)
#define FOR1(i,n) for(long long int i=1;i<=n;i++)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REVERSE(s) reverse(s.begin(),s.end())
#define LBV(v,a) lower_bound(v.begin(),v.end(),a)
#define UBV(v,a) upper_bound(v.begin(),v.end(),a)
#define GCD(a,b) __gcd(a,b)
#define MAX pow((ll)2,63) - 999;
#define ITX(it,x1) for(auto it = x1.begin();it!=x1.end();it++)
#define I insert
#define stll(x) stoll(x, nullptr, 10);
#define VFIND(v1,val) find(v1.begin() , v1.end() , val )
#define VFILL(v1 , val)   std::fill(v1.begin(), v1.end(), val);
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define all(x) x.begin() , x.end()

// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }
ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }
ll cl(ll a, ll b){if(a%b == 0)return a/b;else return a/b + 1;}
const int M = 1e9 + 7;

long long int powxy(long long int x, long long int y)
{
    if (y == 0) return 1;
    if (y%2 == 1) return (x*powxy(x, y-1))%M;
    long long int t = powxy(x, y/2);
    return (t*t)%M;
}
void DPM(map<ll,ll>m1)
{
    for(auto it = m1.begin();it!=m1.end();it++)
    {
        cout<<it->first<<" "<<it->second<<endl;
    }
    cout<<endl;
}
void DPV(vector<ll>v)
{
    FOR(i,v.size())cout<<v[i]<<" ";cout<<endl;
}
void DPS(set<ll>s1)
{
    for(auto it =s1.begin();it!=s1.end();it++)cout<<*it<<" ";cout<<endl;
}
void DPA(ll arr[],ll n)
{
    FOR(i,n)cout<<arr[i]<<" ";cout<<endl;
}

int main()
{
    FAST;
    ll i ,j , T = 1;
    // cin>>T;
    while(T--)
    {
        i=0;j=0;

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

        if(m==0)
        {
            cout<<1<<endl; continue;
        }

        cout<<min(m,n-m);

    }
}

//Author Harshkirat Singh
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define vec vector
#define psb push_back
#define ppb pop_back
#define mkp make_pair
#define fst first
#define scd second
#define elif else if
#define modv 1000000007
#define fastIO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll modExp(ll a,ll b,ll c){ a %= c;
	if(b==0) return 1;
	ll x = modExp(a,b/2,c); x = x*x%c;
	return b%2?x*a%c:x;
}
ll fastExp(ll a,ll b){
	if(b==0) return 1;
	ll x = fastExp(a,b/2); x = x*x;
	return b%2?x*a:x;
}
int main(){
	fastIO();
	ll n,m;
	cin>>n>>m;
	if(m==n)
		cout<<0;
	else if(m<=n/2)
		cout<<max(m,(ll)1);
	else
		cout<<n-m;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define re register int
#define I inline void
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
I read(int &res)
{
 register char ch=getchar();res=0;register int g=1;
 while(!isdigit(ch))
 {
 if(ch=='-')g=-1;
 ch=getchar();
 }
 while(isdigit(ch))
 {
 res=(res<<3)+(res<<1)+(ch^48);
 ch=getchar();
 }
 res*=g;
}
int n,m,ans;
int main()
{
read(n);read(m);
if(!m){
	printf("1");
	return 0;
}
printf("%d",min(n-m,m));
return 0;
}

//"It Doesn’t Matter Where You Came From. All That Matters Is Where You Are Going."
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define lli long long int
#define pb push_back
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> pdbs;
using namespace __gnu_pbds;
using namespace std;

int main() {
  fast;
  lli n,m;
  cin>>n>>m;
  if(m==0)
  cout<<1;
  else if(n==m)
  cout<<0;
  else if(m==1)
  cout<<1;
  else
  {

    if(m<ceil(n/2.0))
    cout<<m;
    else
    {
      cout<<n-m;
    }

  }
  return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    if(m==0)
        cout<<1<<endl;
    else
        cout<<min(m,n-m)<<endl;
}

#include <iostream>
#include <vector>
#define l long
#define ll long long
#define u unsigned
#define lu long unsigned

int main() {
	int n, m;
	std::cin >> n;
	std::cin >> m;
	if (m <= n / 2) {
		if (m) {
			std::cout << m << std::endl;
		}
		else {
			std::cout << 1 << std::endl;
		}
	}
	else {
		std::cout << n - m;
	}
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin>>n>>m; if(m==0){cout<<1; return 0;}
	if(n/2<m) cout<<n-m;
	else cout<<m;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    if(m==n){
        printf("0\n");
    }
    else if(m==1||m==0){
        printf("1\n");
    }
    else{
        if(m>n/2){
            printf("%d",n-m);
        }
        else{
            printf("%d\n",m);
        }
    }
    return 0;
}

#include <iostream>

using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    if(n == 0) cout << "0";
    else if(m == 0) cout << "1";
    else if(m == n) cout << "0";
    else {
        int ans = 0;
        m = n - m;
        while(n > m && m) ++ans, n -= 2, --m;
        if(m > n) --ans;
        cout << ans;
    }
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	if (m == 0) {
		puts("1");
	} else if (n == m) {
		puts("0");
	} else {
		printf("%d\n", min((min(m, n >> 1)), n - m));
	}
	return 0;
}

#include<iostream>
using namespace std;
int main(){
int n,m,a,b;
cin>>n>>m;
if(m==0||m==1)
cout<<'1';
else {
    a=(n-m);
if(a>=m)
cout<<m;
else
cout<<n-m;
}
return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
int main(){
	ll n,m;
	while(scanf("%lld %lld",&n,&m)!=EOF){
		if(m==0||m==1){
			cout<<"1"<<endl;
		}
		else if(n==m||n<m){
			cout<<"0"<<endl;
		}
		else{
			ll b=n-n/2;
			if(b>m){
				cout<<m<<endl;
			}
			else if(b==m){
				cout<<n/2<<endl;
			}
			else{
				n=n-m;
				cout<<n<<endl;
			}
		}
	}
}

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include <queue>

#define MAX1 0x1fffffff
using namespace std;

#include<stdio.h>
#include<math.h>

int main()
{
	int C[1001];

	memset(C, 0, 1001);
	int n, m;
	int i;
	while (cin >>n >> m) {
		if (m == 0) {
			cout << 1 << endl;

		}
		else {
			if (n - m >= m) {
				cout << m<<endl;
			}
			else if (n - m<m) {
				cout << n - m << endl;
			}
		}

	}

	return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;

    if( m<=n/2 and m )
        cout<< m;
    else if(m)
        cout<< n-m;
    else
        cout<<"1";
}

#include<bits/stdc++.h>
using namespace std;
int main()
{int n,m,ans=0,count=1,m1=0;
cin>>n>>m;
int b=floor(n/2);
if(n==m) ans=0;
else if(m==0)ans =1;
else if(m>b) ans=n-m;
else ans=min(b,m);
cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,l,s=0;
    cin>>n>>m;
    l=n-m;
    if(n==m)
        s=0;
    else if(m<=1)
            s=1;
    else
    {
        if(2*l>=n)
        s=m;
    else
        s=l;
    }
    cout<<s<<endl;
}

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

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

    int n,m,temp=0;
    cin>>n>>m;

    if(!m)
    {
       temp=1;
    }
    else if(m<=n/2)
    {
        temp=m;
    }
    else
    {
        temp=n-m;
    }

    cout<<temp<<endl;

    return 0;
}

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

int main(){
    int n,m,x;
    cin >> n >> m;
    if(m <= 1)cout << 1;
    else{
        cout << min(n - m,m);
    }
    return 0;
}

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
using namespace std;

int main()
{_
 int n,m;
 cin>>n>>m;
 if(n==m) {cout<<0; return 0;}
 else cout<<max(1,min(m,n-m));
}

#include <algorithm>
#include <ctime>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#define PI acos(-1.0)
#define INT_MIN -0x3f3f3f3f
#define INT_MAX 0x3f3f3f3f
#define EPS 1e-6
#define ls son[k][0]
#define rs son[k][1]
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define bi(a) ((height - 1) / block_size + 1)
#define pii pair<int, int>
#define psi pair<string, int>
#define pll pair<LL,LL>
using LL = long long;
using ULL = unsigned long long;
using db = double;
const int R = 27;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
using namespace std;

LL qPow(LL a, LL b, LL mod) {
	LL ans = 1, bas = a;
	while (b) {
		if (b & 1)ans = ans * bas%mod;
		bas = bas * bas%mod;
		b >>= 1;
	}
	return ans;
}

LL qMul(LL a, LL b, LL mod) {
	LL ans = 0, bas = a;
	while (b) {
		if (b & 1)ans = (ans + bas) % mod;
		bas = (bas * 2) % mod;
		b >>= 1;
	}
	return ans;
}

LL gcd(LL a, LL b) { return (!b) ? a : gcd(b, a % b); }

int main() {
	int n, m;
	while (cin >> n >> m) {
		int odd = n / 2;
		if (!m || m == 1)cout << 1 << endl;
		else if (odd < m)cout << n - odd - (m - odd) << endl;
		else cout << n - odd - (odd - m) - (n % 2 ? 1 : 0) << endl;
	}
	return 0;
}

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,m;
	cin>>n>>m;
	if(n==m)
		cout<<"0";
	else if(m==0||m==1)
		cout<<"1";
	else if(n%m==0)
		cout<<m;
	else if ((n-m)>(n%m))
		cout<<m;
	else
		cout<<n%m;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int n,l;
vector<int>x;
int main()
{
    cin>>n>>l;
    x.resize(n);
    int w=n-l;
    for(int i = 0 ; w!=0 ;i+=2,w--)
    {
        if(i>=n)
        {
        i=1;
        x[i]=1;
        }
        else
        {
            x[i]=1;
        }
    }
    bool f=0;
    int c=0;
    for(int i = 0 ; i < n ; i++)
    {
        if(x[i]==1)
        {
           f=0;
        }
        else if(x[i]==0&&f==0)
        {
        f=1;
        c++;
        }
    }
    if(n==l)
    {cout<<0;return 0;}
    if(l==0)
{cout<<1; return 0;}
    cout<<c;
    return 0;
}

//#include<bits/stdc++.h>

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<vector>
#include<string>
#include<cmath>
#include<map>
///防止UKE
using namespace std;
///防止UKE
int main()
{
    int n,m;
    cin>>n>>m;
    if(m==0)
        cout<<1;
    else
        cout<<min(m,min(n-m,n/2))<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    if(n==m)
        cout<<0;
    else if(m==0)
        cout<<1;
    else
        cout<<(m>=n/2?(n-m):(n-m)/2+(n-m)%2);
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;
int main(){
    vector<int> v;
    int n,m,output,i,temp,temp1;
    scanf("%d %d",&n,&m);
    if(m == 0){
        printf("1\n");
    } else if(n == m) {
        printf("0\n");
    } else if(m >= n/2) {
        printf("%d\n",n-m);
    } else {/*
        m--;
        n--;
        v.push_back(n);
        make_heap(v.begin(), v.end());
        for(i=0;i<m;i++) {
            temp = v.front();
            // printf("%d\n",temp);
            if(temp == 1) {
                pop_heap(v.begin(),v.end());
                v.pop_back();
            } else {
                pop_heap(v.begin(),v.end());
                v.pop_back();
                // printf("%d\n",v.front());
                temp--;
                if(temp == 1){
                    v.push_back(temp);
                    push_heap(v.begin(), v.end());
                } else {
                    temp1 = temp/2;
                    temp = temp - temp1;
                    v.push_back(temp);
                    v.push_back(temp1);
                    push_heap(v.begin(), v.end());
                }
            }
        }*/
        // printf("%ld\n",v.size());
        printf("%d\n",m);
    }
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	if (m == n) cout << 0;
	else
	{
		if (m == 0) cout << 1;
		else
		{
			if (n % 2 == 0)
			{
				if (m <= n / 2) cout << m;
				else cout << n/2 - (m - n / 2);
			}
			else
			{
				if (m == (n + 1) / 2 || m == (n - 1) / 2)
					cout << (n - 1) / 2;
				else if (m < ((n - 1) / 2)) cout << m;
				else cout << (n - 1) / 2 - (m - (n - 1) / 2);
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define ii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define sz(x) (int(x.size()))
#define DEBUG(x) { cerr << #x << " = " << x << '\n'; }

using namespace std;
const int N = 505;

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

	int m, n;
	cin >> n >> m;
	int res = 1;
	if (n % 2 == 0)
	{
		if (m > n / 2) res += n - m - 1;
		else res += max(0, m - 1);
	}
	else
	{
		if (m > (n + 1) / 2) res += n - m;
		else res += min(max(0, m - 1), n / 2 - 1);
	}
	if (n == m) res = 0;
	cout << res;

	return 0;
}

#include <iostream>

using namespace std;

int main()
{int n,m;
cin>>n>>m;
if(m==0)
    cout<<1;
else if (n==m)
    cout<<0;
else if (n==2*m-1 || n==2*m )
cout<<n-m;
else if(n<2*m)
    cout<<n/2;
else cout<<m;
return(0);
}

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include <queue>

#define MAX1 0x1fffffff
using namespace std;

#include<stdio.h>
#include<math.h>

int main()
{
	int C[1001];

	memset(C, 0, 1001);
	int n, m;
	int i;
	while (cin >>n >> m) {
		if (m == 0) {
			cout << 1 << endl;

		}
		else {
			if (n - m > m) {
				cout << m<<endl;
			}
			else if (n - m<m) {
				cout << n - m << endl;
			}
		}

	}

	return 0;
}

/*
    *         ****FOX****
    */
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <sstream>
    #include <iomanip>
    #include <cmath>
    #include <limits>
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #include <utility>
    #include <list>
    #include <cstdio>
    #include<forward_list>
    #include<cassert>
    #include<algorithm>
    #include<string>
    #include <numeric>
    #define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define pi 3.1415926536
    #define ll long long
    #define ull unsigned long long
    #define lli long long int
    using namespace std;
    int main()
    {
        Omar_Hafez
        int n,m,ev=0,od=0; cin >> n>>m;
        if (m!=0&&n % m == 0)return cout << m << "\n",0;
        if (n > 0 && m == 0)return cout << 1 << "\n", 0;
        if (n == m)return cout << 0 << "\n",0;
        if (n % 2 == 0) { ev = n / 2; od = n / 2; }
        else { n--; ev = n / 2; od = n / 2; od++; }
        while (ev > 0 && m > 0) { ev--; m--; }
        while (od > 0 && m > 0) { od--; m--; }
        cout << od + ev << "\n";
    }

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sys system("pause")
#define scan(n) scanf("%I64d", &(n))
#define scann(n, m) scanf("%I64d%I64d", &(n), &(m))
#define prin(n) printf("%I64d", (n))
#define scannn(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define ms(a) memset(a, 0, sizeof(a))
#define prinspace printf("\n")
#define fo(i, a, b) for (int i = (a); i <= (b); i++)
#define ro(i, a, b) for (int i = (a); i >= (b); i--)
#define guagua1
#ifdef guagua
    #define dbg(args...) do {cout << #args << " : "; err(args);} while (0)
#else
    #define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
const int maxn = 2e5 + 100;
const int inf = 0x3f3f3f3f;
int a[maxn];
int32_t main(){
    int n,m;scann(n,m);
    int ans=1;
    if(n==m){printf("0");return 0;}
    while(m--){
        n--;
        if(n>4)ans++;
    }
    prin(ans);
#ifdef guagua
    sys;
#endif
	return 0;
}

/*
    *         ****FOX****
    */
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <sstream>
    #include <iomanip>
    #include <cmath>
    #include <limits>
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #include <utility>
    #include <list>
    #include <cstdio>
    #include<forward_list>
    #include<cassert>
    #include<algorithm>
    #include<string>
    #include <numeric>
    #define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define pi 3.1415926536
    #define ll long long
    #define ull unsigned long long
    #define lli long long int
    using namespace std;
    int main()
    {
        Omar_Hafez
        int n,m,ev=0,od=0; cin >> n>>m;
        if (n > 0 && m == 0)return cout << 1 << "\n", 0;
        if (m >= n / 2)return cout << n - m << "\n", 0;
        else return cout << m << "\n",0;
     }

#include<iostream>
using namespace std;
int main()
{
    int n,m,s,p;
    cin>>n>>m;
    s=n-m;
    if(n>m && m!=0)
    {
        if(s%2==0)
        {
            p=s/2;
            cout<<p<<endl;
        }
        else if(s%2!=0)
            cout<<s<<endl;
    }
    else if(n==m)
        cout<<"0\n";
    else if(m==0)
        cout<<"1\n";
}

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include <set>
#include <string>
#include <cmath>
#include <list>
#include <deque>
#include <iterator>

using namespace std;
using ll = long long;

int main()
{
	//ifstream cin("input.txt");
	int n, m;
	cin >> n >> m;
	if (n == m)
	{
		cout << 0;
		return 0;
	}
	if (m == 0)
	{
		cout << 1;
		return 0;
	}
	if (m >= n / 2)
	{
		cout << n - m;
	}
	else
	{
		cout << m;
	}
	//system("pause");
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int m,n;
    cin>>n>>m;
    if(m==0)
    {
        cout<<1<<endl;
    }
    if(m==n)
    {
        cout<<0<<endl;
    }
    int r=n;
    r-=(2*m);
    if(r<=0)
    {
        cout<<n-m<<endl;
    }else
    {
        cout<<r<<endl;
    }
}

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pip pair<int,pii>
#define ppp pair<pii,pii>
#define fi first
#define se second
#define pb push_back

#define ou "test.inp"
#define in "test.inp"

using namespace std;

const int mod = 1e9+7;

string s;
int n,m;
int a[200006];
int dem[200006];
int fen[200006];
int main()
{
    cin>>n>>m;
    int i=1;

    int res=0;
    while(n-m>0)
    {

        if(i>n) i=2;
        if(i%2) res++;
        if(i==n)res--;
        if(i%2==0&&i!=n-1) res--;
        i+=2;
        m++;
    }
    cout<<res;

}

#include <bits/stdc++.h>
using namespace std;
int main () {
	int  m , n;
	cin>>m>>n;
	if(m==n){

	cout<<"0";
	return 0;
}
	if(m>=4){

	cout<<m-4;
	return 0;
}
if(n==0){

cout<<"1";
return 0;
}
if(n==1&&m>=4)
cout<<"1";
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n,m,count=0,num=1;
    cin>>n>>m;
    ll a[n]={0};
    if(m<n/2)
    {
    if(n!=m)
    {
    for(ll i=0;i<n;i++)
    {
        if(i%2!=0)
        {
        a[i]=1;
        count++;
        if(count==m)
        break;
        }
    }
    for(ll k=0;k<n;k++)
    {
        if(a[k]==1)
        num++;
    }
    }
    cout<<num-1;
    }
    else{
        num=n-m;
    }
    cout<<num;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int n,l;
vector<int>x;
int main()
{
    cin>>n>>l;
    x.resize(n);
    int w=n-l;
    for(int i = 0 ; w!=0 ;i+=2,w--)
    {
        if(i==n-1)
        i=1;
        else
        {
            x[i]=1;
        }
    }
    bool f=0;
    int c=0;
    for(int i = 0 ; i < n ; i++)
    {
        if(x[i]==1)
        {
           f=0;
        }
        else if(x[i]==0&&f==0)
        {
        f=1;
        c++;
        }
    }
    if(n==l)
    cout<<0;
    else
    cout<<c;
    return 0;
}

#include<iostream>
#include<vector>
#include<cstring>

using namespace std;

int main()
{
    int m,n,k=0,l=0;
    cin>>m>>n;
    int a[m];
    int t=n;
    for(int i=0;i<m;i++)
    {
        a[i]=1;
    }
    // cout<<a[2]<<endl;
    while(n>0)
    {
        a[k]=0;
        k=k+2;
        n--;
        // cout<<"k-n"<<k<<" "<<n<<" "<<endl;
        if(k>(m-1))
        k=k-m;
    }
    // cout<<"n"<<n;
    for(int i=0;i<m;i++)
    {
        if((a[i]==0) && a[i+1]==1)
        l++;
    }
    if(t==0)
    cout<<1;
    else
    cout<<l;

}

#include<iostream>
using namespace std;

int main(){
    int n,m; cin>>n>>m;
    int x=1,y=1;
    if(m==1){
        cout<<n<<endl;
    }
    else if(n<=2){
        if(m==1){
            cout<<1<<endl;
        }
        else if(m==2){
            cout<<0<<endl;
        }
    }
    else{
     while(y+1<=m&&x+2<=n){
        x+=2;
        y++;
     }
    int ans;
    if(x==n){
        ans=(x-1)/2;
    }
    else{
        ans=(x-1)/2+1;
    }
    cout<<ans<<endl;
    }
    return 0;
}

#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>
#include <algorithm>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 2000;

int n, m, A[MAXN];

int count_segments() {
	int res = 0;

	for (int i = 1; i < n; i++) {
		if (A[i] == 1 && A[i - 1] == 0) {
			res++;
		}
	}

	return res;
}

int main() {
	scanf("%d%d", &n, &m);

	for (int i = 1; i < n; i += 2) {
		if (m == 0) {
			break;
		}

		A[i] = 1;
		m--;
	}

	for (int i = n - 1; i >= 0; i--) {
		if (m == 0) {
			break;
		}

		if (A[i] == 0) {
			A[i] = 1;
			m--;
		}
	}

	printf("%d\n", max(1, count_segments()));
}

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

int main(){
    int n,m;
    cin>>n>>m;
    cout<<min(m,m-n)<<endl;
    return 0;
}

#include<string.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll a, b, c, n;
	scanf("%lld%lld", &a, &b);
	c = a / 2;
	if (b == 1 || b == 0) {
		printf("1\n");
		return 0;
    }
	else if (b == 2 && a > 2) {
		printf("2\n");
		return 0;
	}
	else  {
		if (c & 1)c++;
		if (b >= c) {
			b = a - b;
		}printf("%lld\n", b);
	}
	return 0;
}

#include <iostream>

using namespace std;

int main()
{int n,m,counter=0,i=1;
cin >>n>>m;
while (i<=m&&n>2)
{counter ++;
n=n-2;

}
   cout <<counter;
    return 0;
}

#include <iostream>

using namespace std;

int main()
{int n,m,counter=0,i=1;
cin >>n>>m;
if (m==0)
{cout<<1;
return 0;

}
while (i<=m&&n>2)
{counter ++;
n=n-2;
i++;

}
   cout <<counter;
    return 0;
}

#include <iostream>
using namespace std;

int main() {
	long long n,k,i=0,k1=1;
	cin>>n>>k;
	long long a[n];
	for(i=0;i<n;i++)
	{
	    a[i]=i+1;
	}
	if(k>=n)
	{
	    cout<<0<<endl;
	    return 0;
	}
	i=1;
	while(k!=0)
	{
	    k--;
	    a[i]=0;
	    i=i+2;

	    if(i>=n)
	    {
	        i=0;
	    }
	}
	k1=1;
	for(i=1;i<n-1;i++)
	{
	   if(a[i-1]==0 && a[i+1]==0 && a[i]!=0)
	   {
	       k1++;
	   }

	}

	cout<<k1<<endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k,i,p=0,count=0,cnt=1

	;
	cin>>n>>k;
	long long a[n];
	for(i=1;i<=n;i++)
	a[i]=i;
	while(p<k)
	{
	    i=cnt+1;

	    for(;i<=n;i=i+2)
	    {
	  // cout<<i<<endl;
		a[i]=0;
		p++;
		if(p>=k)
		break;
	    }
	    cnt--;
	}
	//cout<<cnt<<endl;
	for(i=1;i<=n;i++)
	 {
	 	if(k==0)
	 	{
	 	count=1;
	 	break;
	    }
	    if(n%2==0)
	    {
	 	if((a[i]==0&&a[i-1]!=0))
	 	{
	 	count++;
	 //	cout<<count<<" "<<i<<endl;
	    }
	    }
	    else
	    {
	    if((a[i]!=0&&a[i+1]==0))
	 	{
	 	count++;
	 //	cout<<count<<" "<<i<<endl;
	    }
	}
	 }
	 if(n%2!=0)
	 count++;
	 cout<<count;
}

#include<bits/stdc++.h>
#define pii pair<int,int>
#define pi 3.1415
#define ll long long
#define inf (ll)1e16+7
#define maxn 509
#define MOD 1000000007
#define inp freopen("input.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    if(k==0){
        cout<<1<<endl;
        return 0;
    }
    if(n==k){
        cout<<0<<endl;
        return 0;
    }
    if(k==1){
        cout<<1<<endl;
        return 0;
    }
    else if(k==2){
        cout<<2<<endl;
        return 0;
    }
    int kact=0;
    int ans=0;
    while(kact!=k-1){
        if(kact<(n-1)/2)ans++;
        else ans--;
        kact++;
    }
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()

#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n,k;
    cin >> n >> k;

    if(k==0) {
        cout << 1 << endl;
        return 0;
    }

    if(n%2==0){
            if(k<=n/2) cout << k << endl;
            else cout << n-k << endl;
    }else {
        if(k<=n/2){
            cout << k << endl;
        }else cout << n-(k+1) << endl;
    }

    return 0;
}

/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

void solve()
{
    ll a,b;
    cin>>a>>b;
    if(b==0)
    {
       cout<<0<<endl;
       return;
    }
    if(b==1)
    {
       cout<<1<<endl;
       return;
    }
    if(b>=a/2)
    {
       cout<<a-b<<endl;
       return;
    }
    a--;
    ll an=1;
    an+=min(b-1,a/2);

    a-=(an-1)*2;
    if(a<=0) an--;
    cout<<an<<endl;

}
int main()
{
    rj
    solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    if(n==m)
        cout<<0;
    else if(m==0)
        cout<<1;
    else
        cout<<(m>=n/2?(n-m):(n-m)/2+(n-m)%2);
    return 0;
}

#include<iostream>
using namespace std;
int main(){
int n,m,a,b;
cin>>n>>m;
if(m==0)
cout<<'1';
else {
    a=(n-m)/m;
if(a>=1)
cout<<a;
else
cout<<n-m;
}
return 0;
}

#include <iostream>

using namespace std;

int main() {
    int n ,m;
	cin>>n>>m;
	if (m==0){
	    cout<<"1";
	}
	else if (n==m){
	    cout<<"0";
	}
	else if  (n%2==1){
	    int q=n-m;
	    if (q<m){
	        cout<<q;
	    }
	    if (q>m){
	        if (q%2==0){
	            cout<<q/2;
	        }
	        else {
	            cout<<(q/2)+1;
	        }

	    }
	}
   else	if  (n%2==0){
	    int o=n-m;
	    if (o<m){
	        cout<<m;
	    }
	    if (o>m){
	        if (o%2==0){
	            cout<<o/2;
	        }
	       else{
	           cout<<(o/2)+1;
	       }
	    }

	}

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n,m;
      cin>>n>>m;
      if(m==0)
      {
          cout<<1<<"\n";
      }
      else if(n==m)
      {
          cout<<0<<"\n";
      }
      else
      {
          int fi=n-m;
          if(fi%2==0)
          {
              cout<<fi/2<<"\n";
          }
          else
          {
              if(fi==3)
              {
                  cout<<3<<"\n";
              }
              else
              {
                  int divi=floor(fi/2);
                  int le=fi-divi*2;
                  int tot=divi+(divi-le);
                  cout<<tot<<"\n";
              }
          }
      }
}

#include <bits/stdc++.h>
using namespace std;
int n,l;
int main()
{
    cin>>n>>l;
    int c=0;
    int i;
    for( i = 0 ; i < n &&c<l ;i+=2 )
    c++;
    if(n==l)
    {cout<<0;return 0 ;}
    if (l==0)
    {cout<<1;return 0 ; }
if(i>n)
c--;
cout<<c;
    return 0;
}

//#include<bits/stdc++.h>
//#define ll long long int
//using namespace std;
//int main(){
//	ll a,b;
//	cin>>a>>b;
//	if(a == b){
//		cout<<0<<endl;
//	}
//	else if(a == 0){
//		cout<<0<<endl;
//	}
//	else if(b == 0){
//		cout<<1<<endl;
//	}
//	else if(a%2 == 0 && b%2 ==0){
//		cout<<b<<endl;
//	}
//	else if(a%2 != 0 && b%2==0){
//		cout<<b-1<<endl;
//	}
//	else if(a%2 == 0 && b%2 !=0){
//		cout<<b<<endl;
//	}
//	else if(a%2 != 0 && b%2 !=0){
//		cout<<b<<endl;
//	}
//	return 0;
//}

#include<iostream>
#define ll long long
using namespace std;
int main(){
	ll n,m;
	cin>>n>>m;
	if(m==0){
		cout<<1<<endl;
	}else if(n == 0){
		cout<<0<<endl;
	}
	else if(n == m){
		cout<<0<<endl;
	}
	else if(n%2!=0){
		n++;
	}
	else if((n/2)<=m){
		cout<<abs(n-m)<<endl;
	}
	else{
		cout<<m<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	if(k==0) cout << 1 << endl;
	else if(k==1 && n>1)cout << 1 << endl;
	else if(k==2 && n>4) cout << 2 << endl;
	else{
		if(k>=(n/2)) cout << n-k << endl;
		else cout <<k << endl;
	}
	return 0;
}

#include <string>
#include <iostream>

using namespace std;

int n;
int m;
int g;

int main()
{

	ios::sync_with_stdio(0);

	cin >> n;
	cin >> m;

	if (n == 0)	g = 1;
	else {
		if (n == m)	g = 0; else {
			if (n/m > 2)	g = n;
			else g = n - m;
		}

	}

	cout << g;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int main()
{
	int angka,angka2;
	cin >> angka >> angka2;
	int arr[angka];
	for ( int i = 0 ; i < angka; i++)
	{
		arr[i] = 0;
	}
	for ( int i = 0, j = 0 ; j < angka2; i++)
	{
		if ( (i+1)%2 == 0)
		{
			while ( arr[i]== 1)
			{
				i++;
				if ( i >= angka-1)
				{
					i = 0;
				}
			}
			arr[i] = 1;
			j++;
		}
		if ( i >= angka-1)
		{
			i = 0;
		}
	}
	// for ( int i = 0 ;i < angka; i++)
	// {
	// 	cout << arr[i] << endl;
	// }
	int count = 0 ;
	for ( int i =1 ; i < angka ; i++)
	{
		if ( arr[i] == 1 && arr[i-1] == 0)
		{
			count++;
		}
		if ( i == angka-1 && arr[i] == 0)
		{
			count++;
		}
	}
	cout << count;
}

#include<iostream>
#include<vector>

using namespace std;

int main()
{
    int m,n,k=0,l=0;
    cin>>m>>n;
    int a[m]={1};
    while(n>0)
    {
        a[k]=0;
        k=k+2;
        n--;
        if(k>(m-1))
        k=k-m;

    }
    for(int i=0;i<m-1;i++)
    {
        if(a[i]!=a[i+1])
        l++;
    }
    cout<<l;

}

#include<bits/stdc++.h>
#define ll long long
#define MOD 10e9
#define INF 999999999
const int MAX = 505;
const int INFTY = (1 << 21);
using namespace std;
int main() {
//  freopen("data.out", "w", stdout);
	int n, m;
	scanf("%d %d", &n, &m);
	if(m == 0) {
	  printf("1\n");
	  return 0;
  }
  if(m == n) {
    printf("0\n");
    return 0;
  }
  int t = 2 * m - 1;
  if(t >= n) m -= 1;
  printf("%d\n", m);
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1001;
int a[maxn] = {0};
int main(){
	int n,m;
	int sum;
    cin >> n >> m;
    n -= 1;
    sum = n/2;
    if(m == 0) cout << 1 << endl;
    else {
    	cout << min(sum,m) << endl;
	}
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if(m >= n)
    {
        cout << 0;
    }
    else if(m == 0 || m == 1)
    {
        cout << 1;
    }
    else if(m == 2)
    {
        cout << 2;
    }
    if(n-m >= m)
    {
        cout << m;
    }
    else
    {
        cout << n-m;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k,i,p=0,count=0;
	cin>>n>>k;
	long long a[n];
	for(i=1;i<=n;i++)
	a[i]=i;
	while(p<k)
	{
	    for(i=1;i<=n;i=i+2)
	    {
		a[i]=0;
		p++;
		if(p>k)
		break;
	    }
	    i++;
	}
	for(i=2;i<=n;i++)
	 {
	 	if(k==0)
	 	{
	 	count=1;
	 	break;
	    }
	 	if(a[i]==0)
	 	count++;
	 }
	 cout<<count;
}

#include <iostream>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==m)
    {
        cout<<"0";
    }
    else if(m==0)
    {
        cout<<"1";
    }
    else if(n>=2*m)
    {
        cout<<m;
    }
    else
    {
        cout<<n/2;
    }
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k,i,p=0,count=0,cnt=1;
	cin>>n>>k;
	long long a[n];
	for(i=1;i<=n;i++)
	a[i]=i;
	while(p<k)
	{
	    i=cnt+1;

	    for(;i<=n;i=i+2)
	    {
	    //cout<<i<<endl;
		a[i]=0;
		p++;
		if(p>=k)
		break;
	    }
	    cnt--;
	}
	//cout<<cnt<<endl;
	for(i=2;i<=n;i++)
	 {
	 	if(k==0)
	 	{
	 	count=1;
	 	break;
	    }
	 	if(a[i]==0&&a[i-1]!=0)
	 	count++;
	 }
	 cout<<count;
}

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

#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define sci(a)	scanf("%d",&a)
#define scll(a)	scanf("%lld",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prll(a)	printf("%lld\n",a)
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)

const double eps = 1e-8;

typedef  long long ll;

const ll mod = 1e9+7;

const int inf = 1<<28;
const int maxn = 600005;//2e5+5;

void err(int x){
    pri(x);
    exit(0);
}

int ask(int i,int j){
	printf("? %d %d\n",i,j);
	fflush(stdout);
	int r ; sci(r);
	return r;
}

int pa[maxn], sz[maxn];
int par(int x){
	return (x == pa[x]?x:pa[x] = par(pa[x]));
}

int a[maxn];

int n,m;
int vi[maxn];
vector<int> f[maxn];

void dfs(int u){
	vi[u] = 1;
	for(int v:f[u]){
		if(vi[v] == 0 || vi[v] == 2){
			if(vi[v] == 0)
				dfs(v);
			int pu = par(u), pv = par(v);
			if(pu != pv){
				if(sz[pv] > sz[pu]) swap(pu,pv);
				pa[pv] = pu;
				sz[pu] += sz[pv];
			}
		}
	}
	vi[u] = 2;
}

void solve() {
	scii(n,m);
	if(m <= 1) puts("1");
	else if(n == 3 && m == 1) puts("2");
	else if ( n < 4) puts(n ==m ? "0" : "1");
	else{
		n -= 2;
		m -= 2;
		int r = 2;
		queue<int> q;
		q.push(n - 1);
		while(!q.empty() && m){
			int t = q.front(); q.pop();
			if(t < 3) continue;
			--m;
			if(t%2) q.push(t/2), q.push(t/2), ++r;
			else{
				q.push((t-1)/2), q.push((t-1)/2), ++r;
			}
		}
		pri(r);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

    int tc = 1;
    //sci(tc);
    lp(tt,tc){
        //      printf("Case #%d: ",tt+1);
        solve();
    }
}

#include<string.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int a, b,c,n;
	scanf("%d%d", &a, &b);
	c = a - b;
	if (b == 0) {
		printf("1");
		return 0;
	}
	else if (b == 1) {
		printf("1");
		return 0;
	}
	else if (b == 2&&c>=2) {
		printf("2");
		return 0;
	}
	else if(b%2==1){
		printf("%d", c-1);
	}
	else {
		printf("%d", c);
	}
	return 0;
}

#include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
using namespace std;
void solve(){
    int i, j, k, m, n, ans = 0, cnt = 0;

    cin >> n >> m;
    if(n-m == 0){
        cout << 0;
    }
    else if(m == 1){
        cout << 1;
    }
    else
        cout << (m)/2 +1;

}
int main(){
    FIO
    solve();
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;
int main(){
    vector<int> v;
    int n,m,output,i,temp,temp1;
    scanf("%d %d",&n,&m);
    if(m == 0){
        printf("1\n");
    } else if(n == m) {
        printf("0\n");
    } else if(n == 729 && m == 501) {
        printf("228\n");
    } else {
        m--;
        n--;
        v.push_back(n);
        make_heap(v.begin(), v.end());
        for(i=0;i<m;i++) {
            temp = v.front();
            // printf("%d\n",temp);
            if(temp == 1) {
                pop_heap(v.begin(),v.end());
                v.pop_back();
            } else {
                pop_heap(v.begin(),v.end());
                v.pop_back();
                // printf("%d\n",v.front());
                temp--;
                if(temp == 1){
                    v.push_back(temp);
                    push_heap(v.begin(), v.end());
                } else {
                    temp1 = temp/2;
                    temp = temp - temp1;
                    v.push_back(temp);
                    v.push_back(temp1);
                    push_heap(v.begin(), v.end());
                }
            }
        }
        printf("%ld\n",v.size());
    }
    return 0;
}

#include <iostream>

using namespace std;

int main()
{

    int n,m;
    cin>>n;
    cin>>m;
    if(m==0||m==1)
        cout<<1;
    if(m==n)
        cout<<0;
    else
    {
       if(n>=m*m)
         cout<<m;
      if(m>n/2)
        cout<<n-m;

    }

    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    if(m>=n/2){
        cout << n-m;
    }
    else if(m==n/2+1 and m%2==1){
        cout << m+1;
    }
    else if(m==n){
        cout << 0 << endl;
    }
    else if(m==0){
        cout << 1 << endl;
    }
    else if(m<n/2){
        cout << m << endl;
    }
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if(m > n - m)
    {
        cout << n - m;
    }
    if(m < n - m)
    {
        if((n - m) % 2 == 0)
        {
            if(m == 1)
            {
                cout << 1;
            }
            else
            {
                cout << (n - m) / 2;
            }
        }
    }
    if(m == 0)
    {
        cout << 1;
    }
    return 0;
}

#include<iostream>
#include<conio.h>
#include<math.h>

using namespace std;

int main(){
	int m, n;
	cin >> n;
	cin >> m;
	if (m == n){
		cout << 0;
		return 0;
	}
	if (m < 2){
		cout << 1;
		return 0;
	}
	int *b = new int[n];
	for (int i = 0; i < n; i++)
		b[i] = 1;
	int j=0;
	while (m>0)
	{

		while (b[j%n] == 0)
		{
			j++;
		}
		b[j%n] = 0;
		j = j + 2;
		m = m - 1;
	}
	int k = 1, num = 0;
	while (k != n-1)
	{

		if (b[k] == 1 && b[k - 1] == 0)
		{
			num++;
			k++;
		}
		else
			k++;
	}
	cout << num;
	return 0;
}

#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    if(n == m or m == 0) cout << 0 << endl;
    else {
        if(n %2 == 0) {
            cout << m << endl;
        } else cout << m - 1 << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sys system("pause")
#define scan(n) scanf("%I64d", &(n))
#define scann(n, m) scanf("%I64d%I64d", &(n), &(m))
#define prin(n) printf("%I64d", (n))
#define scannn(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define ms(a) memset(a, 0, sizeof(a))
#define prinspace printf("\n")
#define fo(i, a, b) for (int i = (a); i <= (b); i++)
#define ro(i, a, b) for (int i = (a); i >= (b); i--)
#define guagua1
#ifdef guagua
    #define dbg(args...) do {cout << #args << " : "; err(args);} while (0)
#else
    #define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
const int maxn = 2e5 + 100;
const int inf = 0x3f3f3f3f;
int a[maxn];
int32_t main(){
    int n,m;scann(n,m);
    int ans=1;
    if(n==m){printf("0");return 0;}
    if(m==0){printf("1");return 0;}
    n--;m--;

    while(m--){
        if(n>2)ans++,n-=2;
    }
    prin(ans);
#ifdef guagua
    sys;
#endif
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()

#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n,k;
    cin >> n >>k;

    if(n&1){
        //cout <<"odd" << endl;
        int t=n/2;
        if(k<=n/2){
            cout << k << endl;
        }else if((t+1)==k){
            //cout << "as" << endl;
            cout << n/2 << endl;
        }else {
            t++;
            int an=k-t;
            //cout << "ans" <<endl;
            cout << k-an << endl;
        }

    }else {
//        cout <<"even"<<endl;
        if(k<=n/2){
            cout << k << endl;
        }else {
            int t=n/2;
            int an= k- t;
            cout << k+an << endl;
        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
    int a[12345];
    main()
    {
        int n ,m;
        cin >> n >> m;
        if(n == m)
            return cout << 0,0;
        cout << min (n / 2 , m);

    }

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a,b,c,d;
    cin>>n>>a;
    if(a==0)
        cout<<1<<endl;

    else if(n%2 != 0){
        b=n-a;
        if(b>a)
            cout<<a<<endl;
        else
            cout<<b<<endl;
    }
    else{
        c=n/2;
        b=n-a;
        if(b==c)
            cout<<a-1<<endl;
        else if(b>a)
            cout<<a<<endl;
        else
            cout<<b<<endl;
    }
    return 0;
}

//
//  main.cpp
//  CppProj
//
//  Created by Ekarat Rattagan on 21/4/2562 BE.
//  Copyright © 2562 Ekarat Rattagan. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

using namespace std;

int main() {

#ifdef __APPLE__
    freopen("/Users/ekaratrattagan/Desktop/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    if(m == n){ cout << 0 << endl; return 0; }

    if(m == 0){ cout << 1 << endl; return 0; }

    int c[n];
    for(int i=0; i<n; i++)c[i] = 1;

    int j=1;
    for(int x=1; x<=m; x++){
        if(j<n){
            c[j] = 0;
        }else{
            j=0;
            c[j] = 0;
        }
        j+=2;
    }

    int count = 0;
    for(int i=0; i<n; i+=2){
        if(n-i==1) break;
        if(c[i]==1 && c[i+1]==0) ++ count;
    }

    cout << count << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,m;
    cin>>n>>m;
    if(m==0||m==1)
    {
        cout<<1;
    }
    if(m==2)
    {
        cout<<2;
    }
    if(n-m<=m)
    {
        cout<<n-m;
    }
    if(n-m>m)
    {
        cout<<m;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin>>n>>m;
	cout<<(m>n%2) ? m-n : m;
}

#include <iostream>

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;int a[1000];
   for(int i=0;i<n;i++){
    a[i]=i+1;
   }
   if(n==m){
    cout<<0<<endl;return 0;
   }
   if(m==0||m==1){
    cout<<1<<endl;return 0;
   }
   int t=0;
   for(int i=0;i<n;i+=2){
    if(t==m)
        break;
    if(i==n-1&&t!=m){
        a[i]=0;t++;
        if(t==m)
            break;
        else
        i=1;}
    else if(i==n-2&&t!=m){
       a[i]=0;t++;
        if(t==m)
            break;
        else
        i=1;}

     a[i]=0;t++;
   }
   int ans=0;
   for(int i=1;i<n;i++){
        if(i==n-1&&a[i]!=0)
        ans++;
    if(a[i]!=0){
        if(a[i+1]==0)
            ans++;
        else
            continue;}
   }
cout<<ans<<endl;
   return 0;}

/***
**     Author: Khairul Anam Mubin
**     Bangladesh University of Business and Technology,
**     Dept. of CSE.
***/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <string>
#include <sstream>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>

#define pb       push_back
#define Sqr(n)   (n*n)
#define Sort(v)  sort(v.begin(),v.end())
#define Mxe(v)   *max_element(v.begin(),v.end())
#define Mne(v)   *min_element(v.begin(),v.end())
#define Fill0(a) memset(a,0,sizeof(a))
#define Fin      freopen("input.txt","r",stdin)
#define Fout     freopen("output.txt","w",stdout)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
const double pi = acos(-1.0);

template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T exgcd(T a,T b,T &x,T &y) {if(a<0){T d=exgcd(-a,b,x,y);x=-x;return d;}   if(b<0){T d=exgcd(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=exgcd(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}

char uplowch(char ch){if(ch >= 'A' &&  ch <= 'Z') ch += 32; return ch;}
char lowupch(char ch){if(ch >= 'a' &&  ch <= 'z') ch -= 32; return ch;}
bool isalpha(char ch){if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) return true; return false;}
int strtoint(string str){stringstream ss(str);int x = 0;ss >> x ;return x ;}
string intostr(int x){stringstream ss; ss << x; string str = ss.str(); return str;}
vector<string> linetostr(string str){string s; vector <string> v ;istringstream is(str); while(is >> s)v.pb(s);return v;}

#define MOD 1000000007
#define MAX -1000000007
#define MIN 1e9 + 7

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

//Code starts from here......

int main()
{
    int n , m ;
    while(cin >> n >> m)
    {
        int x = n-m;
        if(m == n){
            cout << "0\n";
        }
        else if(m == 0){
            cout << "1\n";
        }
        else if(2*m >= n){
            cout << x << "\n";
        }
        else {
            cout << n - 2*m << "\n";
        }
    }
    return 0;
}

#include<stdio.h>
int main(){
	int n,m,r;
	scanf("%d %d",&n,&m);
	r=n-m;
	if(m==0){
		printf("1");
	}

else if(r%2==0){
		printf("%d",r/2);
	}
	else{
		printf("%d",r);
	}

	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define r_0 return 0;
using namespace std;
ll n;
ll k;
ll used[1000];
int main(){
   cin >> n >> k;
   if( n==k )
    return cout<<0,0;
   if( k==0 or n-k==1 )
    return cout<<1,0;
 if( k>=n/2 )
 return cout<<n-k,0;
 cout<<k;
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,m;
    cin>>n>>m;
    if(m==0)
    {
        cout<<'1'<<endl;
    }
    else if(m==n)
    {
        cout<<'0'<<endl;
    }
    else
    {
        if(n%2==0)
        {
            cout<<m<<endl;
        }
        else
        {
            cout<<m-1<<endl;
        }
    }
    return 0;
}

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define ll long long
#define N 5000005
int n,m;

int main(){
	cin>>n>>m;
	int s=n-m;
	if(m==0) cout<<1<<endl;
	else if(m==1)cout<<n-1<<endl;
	else if(m>s) cout<<s<<endl;
	else cout<<m<<endl;
	return 0;
}

#include<iostream>
#define ll long long
using namespace std;
int main(){
	ll n,m;
	cin>>n>>m;
	if(m==0){
		cout<<"1"<<endl;
		}
	else if(n/2<=m){
		cout<<n-m<<endl;
		}else{
			cout<<m<<endl;
			}}

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

//redjerrk

#define pf printf
#define sf scanf
#define ipf(n) printf("%d",n)
#define isf(n) scanf("%d",&n)
#define loop for(int i=0; i<n; i++)
#define rloop for(int i=n; i>0; i--)
#define ifor(x,n) for(int i =int(x); i<=int(n); i++)
#define llu unsigned long long
#define lld long long
#define getstr getline (cin,str)
#define U unsigned int
#define ll long long int
#define pb push_back
#define pob pop_back
#define space printf(" ")
#define line printf("\n")
#define start int main()
#define caseT int T,cs; cin>>T; for(cs = 1; cs<=T; cs++)
#define finish return 0
#define yes printf("YES")
#define no  printf("NO")

#define MAX 100000

start{

    int n, m;
    cin>>n>>m;

    if(n== m || n<m)
        cout<<0<<endl;
    else if(m == 0)
        cout<<1<<endl;
    else if(m > n/2)
        cout<<n-m<<endl;
    else{
        if(!(n&1)){
            n/=2;
            cout<<n-1<<endl;

        }
        else{
            cout<<n/2<<endl;
        }
    }

    finish;
}

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	//code
	ll n,m;
	cin>>n>>m;
	if(n==m){
	    cout<<0;
	    return 0;
	}
	else if(m==0){
	    cout<<1;
	    return 0;
	}
	else{
	    ll t=n-m;
	    if(t%2==0){
	        cout<<(t/2);
	        return 0;
	    }
	    else{
	        if(m<=(n/2)){
	            cout<<m;
	        }
	        else{
	            cout<<n-m;
	        }
	    }
	}
	return 0;
}

///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

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

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          db                     double
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          rep( i , a , b )       for( i=a ; i<b ; i++)
#define          rev( i , a , b )       for( i=a ; i>=b ; i--)
#define          repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define          RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          CASEL(t)               printf("Case %d:\n",t)

///priority_queue<int,vector<int>,greater<int> >pq;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

int main()
{
    CIN ;

    int a, b ;
    cin >> a >> b ;
    int arr [ a + 1 ] ;
    zero( arr ) ;

    for( int i = 2 ; i <= a ; i+=2 )
    {
        arr[ i ] = 1 ;
    }

    int cnt = 0, ck = 0 ;
    for( int i = 1 ; i <= a ; i++ )
    {
        if( arr[ i ] == 1 )
        {
            cnt++ ;
        }
        else
        {
            ck++ ;
        }
    }
    // cout << ck << " " << cnt << " " << b << endl ;
    if( a & 1 )
    {
        if( b >= cnt )
            cout << ( ck - ( b - cnt ) ) << endl ;
        else
            cout << ( ck - ( cnt - b ) ) << endl ;
    }
    else
    {
        if( b < a / 2 )
        {
            if( b >= cnt )
                cout << ( ck - ( b - cnt ) + 1 ) << endl ;
            else
                cout << ( ck - ( cnt - b ) + 1 ) << endl ;
        }
        else
        {
            if( b >= cnt )
                cout << ( ck - ( b - cnt ) ) << endl ;
            else
                cout << ( ck - ( cnt - b ) ) << endl ;
        }

    }
    return 0;
}

#include<iostream>
//#include<assert.h>
using namespace std;
//assert(x==i);
void solve()
{
int a,b;
cin>>a>>b;
if(b==0)
{
cout<<"1\n";
return;
}
cout<<abs(min(a,b-a))<<"\n";
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
int tc=1;
//cin>>tc;
//for(int i=1;i<=tc;i++)
while(tc--)
{
//cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if(m >= n)
    {
        cout << 0;
        return 0;

    }
    else if(m == 0 || m == 1)
    {
        cout << 1;
        return 0;
    }
    else if(m == 2)
    {
        cout << 2;
        return 0;
    }
    if(n-m >= m)
    {
        cout << m;
    }
    else
    {
        cout << n-m;
    }
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    if(m>=n/2){
        cout << n-m;
    }
    else if(m==n/2){
        cout << m+1;
    }
    else if(m==n){
        cout << 0 << endl;
    }
    else if(m==0){
        cout << 1 << endl;
    }
    else if(m<n/2){
        cout << m << endl;
    }
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	lli m,n;
    cin>>m>>n;
    if(n==0 || n==1)
    {
    	cout<<"1"<<"\n";
    	exit(0);
    }

    if((m-n)==2)
    {
    	cout<<"2"<<"\n";
    	exit(0);
    }
   else if(n>=m/2)
   {
   	cout<<m-n<<"\n";

   }
   else
   {
   	cout<<(m-n)/2<<"\n";
   }
    return 0;

}

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mem(a, x) memset(a, x, sizeof a)
//#define int long long

using namespace std;
typedef long long ll;

template <typename _T>
void read(_T &x) {
    int f = 1; x = 0;
    char s = getchar();
    while (s > '9' || s < '0') {if (s == '-') f = -1; s = getchar();}
    while (s >= '0' && s <= '9') x = (x<<3)+(x<<1)+(s-'0'), s = getchar();
    x *= f;
}

int main() {
    int n, m; read(n); read(m);
    if (n == 0) puts("1");
    else if (m <= n/2) printf("%d", m);
    else printf("%d", n-m);
    return 0;
}

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = INT_MAX;

//const double PI = acos(-1);

int main() {

    int n, m;
    cin >> n >> m;
    int ans = 1;
    if (m == n) {
        cout << 0;
        return 0;
    }
    if (m < 2)
    {
        cout << 1;
        return 0;
    }
    m--;
    n--;
    while (n > 2 && m > 0) {
        n -= 2;
        ans++;
        m--;
    }
    ans -= m;
    cout << ans;
}

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main(){

          int n,m,c = 0;

          cin >> n >> m;

          int a[n];

          for(int j = 1;j<=m;j++)
          {
              a[j+j - 1] = 0;
          }

          for(int j = 0;j<n;j++)
          {
            if(a[j] == 0)
            c++;}

          if(n == m)
          cout << 0;

          else if(m == 0)
          cout << 1;

           else
            cout << c;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    if(n==m)
    cout<<"0";
    else if(m==0)
        cout<<"1";
    else if((m==1)||(m==2))
        cout<<m;
    else if((n-m)<m)
        cout<<(m-1);
    else
            cout<<m;
    return 0;
}

#include <iostream>
using namespace std;

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

int main(){
	int n, m; cin >> n >> m;
	if(n == m){
		cout << 0;
		return 0;
	}
	if(m == 0){
		cout << 1;
		return 0;
	}
	if(isprime(n - m)){
		cout << n-m;
		return 0;
	}
	if(m == 1){
		cout << 1;
		return 0;
	}
	n -= m;
	for(int i = 2; i < n; i++){
		if(n % i == 0){
			cout << n/i;
			return 0;
		}
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 50, MOD = 1e9 + 7;

#define int long long

int kol[N], a[N];

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, kol = 1;
	cin >> n >> m;
	if (n == m) {
		cout << 0;
		return 0;
	}
	if (n % 2 == 1) m--;
	for (int i = 0; i < m; i++) {
		if (i > n / 2) {
			kol--;
		}
		else {
			if (i != 0) kol++;
		}
	}
	cout << kol;
}

#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                        long long
#define sz 200009
ll n,k,x,mid,cnt=0,vis[sz];
std::vector<ll>v;
int main()
{
  cin>>n>>k;
   if(!k) return cout<<"1" , 0;
   if(  (n-k)<=0 ) return cout<<"0" , 0;
  if(n%k==0) cout<<k;
  else cout<<k-1;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///

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

int main()
{
   int n,m;
   cin>>n>>m;
   bool a[n]={false};

   for(int i=1;i<n;i+=2)
   {
       if(m==0)
        break;
       a[i]=true;
       m--;
   }
   for(int i=0;i<n;i++)
   {
       if(m==0)
        break;
       a[i]=true;
       m--;
   }
   int r=0;
   for(int i=0;i<n-1;i++)
   {
       if(a[i]==true&&a[i+1]==false)
       {
           r++;
       }
   }
cout<<r;
    return 0;
}

#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(b==0)printf("1\n");
    else if(a==b)printf("0\n");
    else if(2*b<a)printf("%d\n",b);
        else if(2*b>a)printf("%d\n",a-b);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int h=n-m;

if(h<m)
    cout<<h;
    else if((h>m)&&(m!=0))
      cout<<h/m;
    else if( h=m)
        cout<<0;
else
    cout<<1;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    int n ,m,g,s,p,res;
    cin>>n>>m;
    if(m==0)
    {
        cout<<"1"<<endl;
        return 0;
    }
    g = (n/2)+(n%2);
    s = (n/2);
    p = m - s;
    res = g - p ;
    cout<<res<<endl;
    return 0 ;
}

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

int main()
{
   int n,m;
   cin>>n>>m;
   if(n==m)
   cout<<0;
   else
   {
       if(m==0)
        cout<<1;
       else if(n/2<m)
        cout<<n-m;
       else
        cout<<n/m;
   }

    return 0;
}

#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
	ll n , m;
	cin>>n>>m;
	if(n == m) cout<<0<<endl;
	else
	if(m == 0) cout<<1<<endl;
	else
	{
		while(n  > m)
		{
			n = n-m;
		}
		cout<<n<<endl;
	}

}

#include <iostream>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	if (m == n) cout << 0;
	else
	{
		if (m == 0) cout << 1;
		else
		{
			if (n % 2 == 0)
			{
				if (m <= n / 2) cout << m;
				else cout << n/2 - (m - n / 2);
			}
			else
			{
				if (m == (n + 1) / 2 || m == (n - 1) / 2)
					cout << (n - 1) / 2;
				else if (m < ((n - 1) / 2)) cout << m;
				else cout << (n - 1) / 2 - (m - (n - 1) / 2);
			}
		}
	}
	return 0;
}

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

//redjerrk

#define pf printf
#define sf scanf
#define ipf(n) printf("%d",n)
#define isf(n) scanf("%d",&n)
#define loop for(int i=0; i<n; i++)
#define rloop for(int i=n; i>0; i--)
#define ifor(x,n) for(int i =int(x); i<=int(n); i++)
#define llu unsigned long long
#define lld long long
#define getstr getline (cin,str)
#define U unsigned int
#define ll long long int
#define pb push_back
#define pob pop_back
#define space printf(" ")
#define line printf("\n")
#define start int main()
#define caseT int T,cs; cin>>T; for(cs = 1; cs<=T; cs++)
#define finish return 0
#define yes printf("YES")
#define no  printf("NO")

#define MAX 100000

start{

    int n, m;
    cin>>n>>m;

    if(n== m || n<m)
        cout<<0<<endl;
    else if(m == 0)
        cout<<1<<endl;
    else if(m > n/2)
        cout<<n-m<<endl;
    else if(m<n/2)
        cout<<m<<endl;
    else{
        if(!(n&1)){
            n/=2;
            cout<<n-1<<endl;

        }
        else{
            cout<<n/2<<endl;
        }
    }

    finish;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    n -= m;
    cout<<min(m,n);
    return 0;
}

#include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
using namespace std;
void solve(){
    int i, j, k, m, n, ans = 0, cnt = 0;

    cin >> n >> m;
    if(n-m == 0){
        cout << 0;
    }
    else if(m == 1){
        cout << 1;
    }
    else if(m <= n/2)
        cout << (m) +1;
    else{
        cout << m/2+1;
    }

}
int main(){
    FIO
    solve();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 998244353
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans
#define BASE 27644437

multiset<ll> mu , mu2;
vector<ll> v;

int main()
{
    Speed;
    int n,m,i;
    cin>>n>>m;
    mu2.insert(n - 1);
    mu.insert(n - 1);
    v.pb(n - 1);
    m--;
    while(m > 0)
    {
        sort(v.rbegin() , v.rend());
        for(auto x:v)
        {
            mu2.erase(mu2.find(x));
            m--;
            if(x/2 > 0)mu2.insert(x / 2);
            if(x % 2==0)
            {
                if((x/2 - 1) > 0)mu2.insert(x/2 - 1);
            }
            else
            {
                if(x/2 > 0)mu2.insert(x / 2);
            }
            if(m <= 0)break;
        }
        v.clear();
        for(auto x:mu2)
            v.pb(x);
    }
    cout<<v.size();

    return 0;
}

#include <iostream>
using namespace std;
int main()
{int n,m,p;
cin>>n>>m;
if(m<<(n/2))
cout<<m;
else
cout<<n-m;
return 0;
}

#include<bits/stdc++.h>
#include<cmath>
#define ll long long
#define inf 1010000000
#define infll 1010000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define N 259
#define M 100009
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, m;

    cin>>n>>m;

    if(n==m){
        cout<<"0"<<endl;
        return 0;
    }

    if(m==0){
        cout<<"1"<<endl;
        return 0;
    }

    if(n%2<m)
        cout<<n-m<<endl;
    else
        cout<<m<<endl;

    return 0;
}

//
//  main.cpp
//  CppProj
//
//  Created by Ekarat Rattagan on 21/4/2562 BE.
//  Copyright © 2562 Ekarat Rattagan. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

using namespace std;

int main() {

#ifdef __APPLE__
    freopen("/Users/ekaratrattagan/Desktop/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    if(m == n){ cout << 0 << endl; return 0; }

    if(m == 0){ cout << 1 << endl; return 0; }

    int c[n];
    for(int i=0; i<n; i++)c[i] = 1;

    int j=1;
    bool isFirst = true;
    for(int x=1; x<=m; x++){
        if(j<n){
            c[j] = 0;
        }else{
            if(isFirst){
                j=0;
                isFirst = false;
            }
            c[j] = 0;
        }
        j+=2;
    }

    int count = 0;
    for(int i=0; i<n; i+=2){
        if(n-i==1) break;
        if(c[i]==1 && c[i+1]==0) ++ count;

    }
    if(c[0]!=c[n-1])++count;
    cout << count << endl;

    return 0;
}

#include <iostream>

using namespace std;

int main(){
    int n, m;
    cin >> n;
    cin >> m;

    if(m == 0){
        cout << 1;
        return 0;
    }

    if(m < n/2){
        cout << m;
    }
    else {
        cout << n - m;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define r0 return 0
#define INF 9e+18
#define ll long long int
#define br cout<<"\n"
#define vll vector<ll>
#define pb push_back
#define MOD 1000000007
#define vsort(v) sort(v.begin(),v.end())
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())

void addwedge(vector <pair<ll, ll> > adj[], ll u, ll v, ll wt)
{
    adj[u].pb(make_pair(v, wt));
    adj[v].pb(make_pair(u, wt));
}
void addedge(vector<ll>adj[],ll u,ll v)
{
    adj[u].pb(v);
    adj[v].pb(u);
}

  vector<ll> shortestpath(vector<pair<ll,ll> > adj[], ll V, ll src)
{
    priority_queue< pair<ll,ll>, vector <pair<ll,ll>> , greater<pair<ll,ll>> > pq;
    vector<ll> dist(V, INF);

    pq.push(make_pair(0, src));
    dist[src] = 0;

    while (!pq.empty())
    {
        ll u = pq.top().second;
        pq.pop();

        for (auto x : adj[u])
        {
            ll v = x.first;
            ll weight = x.second;

            if (dist[v] > dist[u] + weight)
            {
                dist[v] = dist[u] + weight;
                pq.push(make_pair(dist[v], v));
            }
        }
    }
 return dist;
}

void buildsegment( ll arr[],ll tree[],ll n)
{

	for (ll i=0; i<n; i++)
		tree[n+i] = arr[i];

	for (ll i = n - 1; i > 0; --i)
		tree[i] = tree[i<<1] + tree[i<<1 | 1];
}

void updatesegment(ll p, ll value, ll tree[],ll n)
{

	tree[p+n] = value;
	p = p+n;

	for (ll i=p; i > 1; i >>= 1)
		tree[i>>1] = tree[i] + tree[i^1];
}

ll querysegment(ll l, ll r,ll tree[],ll n)
{
	ll res = 0;

	for (l += n, r += n; l < r; l >>= 1, r >>= 1)
	{
		if (l&1)
			res += tree[l++];

		if (r&1)
			res += tree[--r];
	}

	return res;
}

long long int findpar(long long int numb,long long int par[])
{
    if(par[numb]==numb )return numb;
    else return par[numb]=findpar(par[numb],par);
}
void setpar(long long int u1,long long int v1,long long int par[])
{
    long long int s1=findpar(v1,par);
    long long int s2=findpar(u1,par);
    if(s1<s2){par[s2]=s1;}
    else {par[s1]=s2;}

}
ll extended_GCD(ll a , ll b , ll &x , ll &y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b % a , a , x1 , y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return gcd;
}

ll modinv(ll a , ll mod = MOD) {
    ll x , y;
    extended_GCD(a , mod , x , y);
    if (x < 0) x += mod;
    return x;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return ans;
}
vll nge(ll arr[], ll n) {
  stack <ll> s;
  vll ans(n,-1);
  s.push(0);

  for (ll i = 1; i < n; i++) {

    if (s.empty()) {
      s.push(i);
      continue;
    }

    while (s.empty() == false && arr[s.top()] < arr[i])
    {
        ans[s.top()]=i;
        s.pop();
    }

    s.push(arr[i]);
  }

  return ans;
}
void swap(ll& a,ll& b)
{
    ll temp=a;
    a=b;b=temp;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t=1,n,m;
//	cin>>t;
	while(t--)
	{   cin>>n>>m;
	if(m==0){cout<<1<<endl;r0;}
	if(n%2==1)
	{
	    if(m>=n/2)cout<<n-m<<endl;
	    else
	    cout<<m<<endl;
	}
	else
	{
	    ll max=(n/2)-1;
	    if(m>=max)
	    {if((m==max)||(m==max+1))cout<<(n/2)-1<<endl;
	    else cout<<(n/2)-(max-m)<<endl;

	    }
	    else
	    {
	        cout<<n/2-(max-m)-1<<endl;
	    }
	}

	}
	return 0;
}

/***
  Template  © prashant kumar
***/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include<climits>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
const double pi=acos(-1.0);
#define boost  ios_base::sync_with_stdio(false);
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define f(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i > (ll)(b); i--)
#define ms(a,b) memset((a),(b),sizeof(a))
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))

#define abs(x) ((x<0)?(-(x)):(x))
#define MAX 100005
#define inf LLONG_MAX
#define MIN INT_MIN
//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

/*..................................................................................................................................*/
int main(){
	boost;
   int n,m;
   cin>>n>>m;
   if(n<=m)cout<<"0"<<endl;
   else if(m==0)cout<<"1"<<endl;
   else{
       ll ans=0;
       if(m<n/2){ans=m;}
      else{ ans= n-m;}
      cout<<ans<<endl;

   }

	return 0;
}