import java.lang.*;
import java.io.*;

/**
 * Created by IntelliJ IDEA.
 * Behdad Hosseini, acm@behdadh.net, behdadh.net
 * Date: Apr 24, 2005
 * Time: 9:44:18 AM
 * A sample code for ACM problem : 1995 Europe Center
 */
public class joseph {

    public static final String file = "joseph";
    public static StreamTokenizer in;
    public static PrintStream out;

    public static int readInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static void main(String[] args) throws IOException {

        in = new StreamTokenizer(new FileReader(file + ".in") );
        out = new PrintStream(file + ".out");

        int k;
        while( (k = readInt()) != 0) {
            // begin of test case
            boolean flag = true;
            int m;
            for (m = k;flag ; m++) {

                int left = 2*k;
                int pos = 0;

                do {
                    pos = (pos + m) % left;
                    left --;
                } while (pos >= k);

                if (left == k- 1) flag = false;
            }

            out.println(m);
        }

        out.close();
    }

}

