#include<bits/stdc++.h> using namespace std; int n; int main(){ while(cin>>n&&n){ cout<<((1<<(n-1))+1)%n<<endl; } return 0; }