"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}

var n,n2,b2,a={};

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main(){
  n = next();
  n2 = 2*n;
  b2 = BigInt(n2);
  for(var i = 2; i *i <= n2; i++){
    if(n2 % i === 0){
      a[i] = 1, n2 /= i;
      while(n2 % i === 0)a[i]++, n2 /= i;
    }
  }
  if(n2 > 1)a[n2] = 1;
  var x = 1;
  for(var i in a){
    x *= (a[i]+1) >> 1;
  }
  n2 = 2*n;
  for(var i = x; i < n2; i += x){
    if(f(i-1))return i-1;
    if(f(i))return i;
  }
  return n2-1;
}

function f(k){
  var kk = k*(k+1);
  if(kk < n2)return;
  if(kk < 9e15){
    if(kk % n2=== 0)return 1;
  }else{
    kk = BigInt(k)*BigInt(k+1);
    if(kk % b2 === 0n)return 1;
  }
}