#include<iostream>
#include<cmath>
#include<list>
#include<climits>
#include<cstring>
#include<set>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<numeric>
using namespace std;
#define etm cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll  long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pdd pair<double , double>
#define pll pair<long long int,long long int>
#define vpl vector<pll >
#define vll vector<ll >
#define vi vector<int >
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     998244353
#define ld                      long double
#define inf                     1e18
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define vvll                    vector<vector<ll>>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define pqll                    priority_queue<ll>
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define umll                    unordered_map<ll,ll>
#define mll                     map<ll,ll>
#define input(a,n)              ll I;rep(I,0,n-1,1) cin>>a[I];
#define countbit                __builtin_popcount // Number of set bits .
#define fbo(k)                  find_by_order // K-th element in a set (counting from zero) .
#define ook(k)                  order_of_key //  Number of items strictly smaller than k .
#define lb                      lower_bound
#define up                      upper_bound
#define in                      insert
//#define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd(ll a,ll b){if(a<b)return gcd(b,a);else if(b==0)return a;else return gcd(b,a%b);}
ll isPrime(ll n){ll p=(ll)sqrt(n);rep(i,2,p,1) if(n%i==0) return 0;return 1;}// reuturn 1 if prime
ll pow(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll ceil(long double a){ll b=a;if(a==b){return b;}else{return b+1;}}
ll floor(long double a){ll b=a;return b;}
ll lcm(ll a,ll b){ return (a*b)/gcd(a,b);}
ll modInverse(ll a, ll m) { return powm(a, m-2, m);}
bool issq(ll n){ ll p=sqrt(n);return p*p==n;}
vll prime;// if i==prime[i] then prime otherwise smallest prime factor of that number
void sieve(ll n)
{
    prime.resize(n+1,1);
    prime[0] = 0, prime[1] = 0;
    for (ll i = 2; i*i <= n; i++)
        if (prime[i])
            for (ll j = i * i; j <= n; j += i)
                prime[j] = 0;
}
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 mulInv(ll a , ll mod=26){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}
ll find(ll num[], ll rem[], ll k,ll prod)
{
    // Compute product of all numbers
    ll result = 0;
    // Apply above formula
    for (ll i = 0; i < k; i++)
    {
        ll pp = prod / num[i];
        result += rem[i] * mulInv(pp, num[i]) * pp;
    }
    return result % prod;
}
ll nCr(ll n,ll k)
{
  ll res = 1;

      // Since C(n, k) = C(n, n-k)
      if ( k > n - k )
          k = n - k;

      // Calculate value of
      // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
      for (ll i = 0; i < k; ++i)
      {
          res *= (n - i);
          res /= (i + 1);
      }

      return res;
}
class DSU
{
 public:vll parent,size;
public: DSU(ll n)
{

        parent.resize(n+1);size.resize(n+1);
        for(ll i=1;i<=n;i++)
            {
            parent[i]=i;
            size[i]=1;
          }
    }
public:ll find_set(ll x)
    {
      if(parent[x]==x)
      {
        return x;
      }
      return parent[x]=find_set(parent[x]);
    }
public:void union_set(ll x,ll y)
    {
        x=find_set(x);y=find_set(y);
        if(x!=y)
        {
          parent[y]=x;
        }
}
};
bool cmp(pair<ll,ll>&p1,pair<ll,ll>&p2)
{
  if(p1.fi==p2.fi)
  {
    return p1.se>p2.se;
  }
  return p1.fi>p2.fi;
}
bool isPalindrome(string s)
{
  ll i,j;
  for(i=0,j=s.length()-1;i<=j;i++,j--)
  {
    if(s[i]!=s[j])
    {
      return 0;
    }
  }
return 1;
}
ll ToInt(char ch)
{
  return ch-'0';
}
char ToChar(ll a)
{
  return a+'0';
}
bool isSubSeq(string str1, string str2, ll m, ll n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;
    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSeq(str1, str2, m-1, n-1);
    // If last characters are not matching
    return isSubSeq(str1, str2, m, n-1);
}
void printVectorPair(vpll v)
{
  for(ll i=0;i<v.size();i++)
  {
    cout<<v[i].fi<<" "<<v[i].se<<"\n";
  }
}
void modBigNumber(string num, ll m)
{
    // Store the modulus of big number
    vector<int> vec;
    ll mod = 0;
    // Do step by step division
    for (int i = 0; i < num.size(); i++) {
        int digit = num[i] - '0';
        mod = mod * 10 + digit;
        int quo = mod / m;
        if((vec.size()!=0)||(quo!=0))        //to remove initiale zeros
        vec.push_back(quo);
        mod = mod % m;
    }
   // cout << "\nRemainder : " << mod << "\n";
   // cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
    return;
}
struct SegmentTree
{
  ll n;
  vll v;
  SegmentTree(ll size)
  {
    n=4*size+1;
    v.resize(n,0);
  }
  void build(ll ar[],ll ipos,ll fpos,ll pos=1)
  {
    if(ipos>fpos)
    return ;
    if(ipos==fpos)
    v[pos]=ar[ipos];
    else
    {
    ll mid=(ipos+fpos)/2;
    build(ar,ipos,mid,pos*2);
    build(ar,mid+1,fpos,pos*2+1);
    v[pos]=v[pos*2]+v[pos*2+1];
    }
  }
  void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
  {
    if(ipos>fpos)
    return ;
    if(ipos==fpos)
    v[pos]+=val;
    else
    {
      v[pos]+=val;
      ll mid=(ipos+fpos)/2;
      if(mid>=index)
      update(index,val,ipos,mid,pos*2);
      else
      update(index,val,mid+1,fpos,pos*2+1);
    }
  }
  ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
  {
    if(ipos>fpos)
    return 0;
    if(l>r)
    return 0;
    ll mid=(ipos+fpos)/2;
    if((l==ipos)&&(r==fpos))
    return v[pos];
    else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);
  }
};
struct BIT
{
vector<ll>bitree;ll n;
BIT(ll n)
{
this->n=n;
bitree.resize(n+1,0);
}
void update(ll idx,ll val)
{
  idx++;
  while(idx<=n)
  {
    bitree[idx]+=val;
    idx+=idx&(-idx);
  }
}
ll Sum(ll idx)
{
  ll sum=0;
  idx++;
  while(idx>0)
  {
    sum+=bitree[idx];
    idx-=idx&(-idx);
  }
  return sum;
}
};
ll sumofdigits(ll a)
{
  ll val=0;
  while(a>0)
  {
    val+=a%10;
    a/=10;
  }
  return val;
}

ll noOfDig(ll n){
  ll cnt=0;
  while(n){
    cnt++;n/=10;
  }
  return cnt;
}

vll arr;
ll n;
bool check(ll x){
  if(x<=0)return false;
  ll ans=0;
  rep(i, 0, n-1, 1){
    if(x<arr[i])return false;
    ans+=max(0ll, x-arr[i]);
  }
  if(ans>=x)return true;
  return false;
}

int main(){
  fastio;
  cin>>n;arr.resize(n);
  rep(i, 0, n-1, 1)cin>>arr[i];
  ll l=1, r=(ll)1e15;
  // ll mid=0;
  while(l<r){
    ll mid=(r+l)/2;
    // cout<<mid<<endl;
    if(check(mid) and !check(mid-1)){
      l=mid;
      break;
    }
    else if(check(mid))r=mid;
    else l=mid;
  }
  cout<<l<<endl;
  return 0;
}


#include<iostream>
#include<cmath>
#include<list>
#include<climits>
#include<cstring>
#include<set>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<numeric>
using namespace std;
#define etm cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll  long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pdd pair<double , double>
#define pll pair<long long int,long long int>
#define vpl vector<pll >
#define vll vector<ll >
#define vi vector<int >
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     998244353
#define ld                      long double
#define inf                     1e18
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define vvll                    vector<vector<ll>>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define pqll                    priority_queue<ll>
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define umll                    unordered_map<ll,ll>
#define mll                     map<ll,ll>
#define input(a,n)              ll I;rep(I,0,n-1,1) cin>>a[I];
#define countbit                __builtin_popcount // Number of set bits .
#define fbo(k)                  find_by_order // K-th element in a set (counting from zero) .
#define ook(k)                  order_of_key //  Number of items strictly smaller than k .
#define lb                      lower_bound
#define up                      upper_bound
#define in                      insert
//#define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd(ll a,ll b){if(a<b)return gcd(b,a);else if(b==0)return a;else return gcd(b,a%b);}
ll isPrime(ll n){ll p=(ll)sqrt(n);rep(i,2,p,1) if(n%i==0) return 0;return 1;}// reuturn 1 if prime
ll pow(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll ceil(long double a){ll b=a;if(a==b){return b;}else{return b+1;}}
ll floor(long double a){ll b=a;return b;}
ll lcm(ll a,ll b){ return (a*b)/gcd(a,b);}
ll modInverse(ll a, ll m) { return powm(a, m-2, m);}
bool issq(ll n){ ll p=sqrt(n);return p*p==n;}
vll prime;// if i==prime[i] then prime otherwise smallest prime factor of that number
void sieve(ll n)
{
    prime.resize(n+1,1);
    prime[0] = 0, prime[1] = 0;
    for (ll i = 2; i*i <= n; i++)
        if (prime[i])
            for (ll j = i * i; j <= n; j += i)
                prime[j] = 0;
}
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 mulInv(ll a , ll mod=26){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}
ll find(ll num[], ll rem[], ll k,ll prod)
{
    // Compute product of all numbers
    ll result = 0;
    // Apply above formula
    for (ll i = 0; i < k; i++)
    {
        ll pp = prod / num[i];
        result += rem[i] * mulInv(pp, num[i]) * pp;
    }
    return result % prod;
}
ll nCr(ll n,ll k)
{
  ll res = 1;

      // Since C(n, k) = C(n, n-k)
      if ( k > n - k )
          k = n - k;

      // Calculate value of
      // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
      for (ll i = 0; i < k; ++i)
      {
          res *= (n - i);
          res /= (i + 1);
      }

      return res;
}
class DSU
{
 public:vll parent,size;
public: DSU(ll n)
{

        parent.resize(n+1);size.resize(n+1);
        for(ll i=1;i<=n;i++)
            {
            parent[i]=i;
            size[i]=1;
          }
    }
public:ll find_set(ll x)
    {
      if(parent[x]==x)
      {
        return x;
      }
      return parent[x]=find_set(parent[x]);
    }
public:void union_set(ll x,ll y)
    {
        x=find_set(x);y=find_set(y);
        if(x!=y)
        {
          parent[y]=x;
        }
}
};
bool cmp(pair<ll,ll>&p1,pair<ll,ll>&p2)
{
  if(p1.fi==p2.fi)
  {
    return p1.se>p2.se;
  }
  return p1.fi>p2.fi;
}
bool isPalindrome(string s)
{
  ll i,j;
  for(i=0,j=s.length()-1;i<=j;i++,j--)
  {
    if(s[i]!=s[j])
    {
      return 0;
    }
  }
return 1;
}
ll ToInt(char ch)
{
  return ch-'0';
}
char ToChar(ll a)
{
  return a+'0';
}
bool isSubSeq(string str1, string str2, ll m, ll n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;
    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSeq(str1, str2, m-1, n-1);
    // If last characters are not matching
    return isSubSeq(str1, str2, m, n-1);
}
void printVectorPair(vpll v)
{
  for(ll i=0;i<v.size();i++)
  {
    cout<<v[i].fi<<" "<<v[i].se<<"\n";
  }
}
void modBigNumber(string num, ll m)
{
    // Store the modulus of big number
    vector<int> vec;
    ll mod = 0;
    // Do step by step division
    for (int i = 0; i < num.size(); i++) {
        int digit = num[i] - '0';
        mod = mod * 10 + digit;
        int quo = mod / m;
        if((vec.size()!=0)||(quo!=0))        //to remove initiale zeros
        vec.push_back(quo);
        mod = mod % m;
    }
   // cout << "\nRemainder : " << mod << "\n";
   // cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
    return;
}
struct SegmentTree
{
  ll n;
  vll v;
  SegmentTree(ll size)
  {
    n=4*size+1;
    v.resize(n,0);
  }
  void build(ll ar[],ll ipos,ll fpos,ll pos=1)
  {
    if(ipos>fpos)
    return ;
    if(ipos==fpos)
    v[pos]=ar[ipos];
    else
    {
    ll mid=(ipos+fpos)/2;
    build(ar,ipos,mid,pos*2);
    build(ar,mid+1,fpos,pos*2+1);
    v[pos]=v[pos*2]+v[pos*2+1];
    }
  }
  void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
  {
    if(ipos>fpos)
    return ;
    if(ipos==fpos)
    v[pos]+=val;
    else
    {
      v[pos]+=val;
      ll mid=(ipos+fpos)/2;
      if(mid>=index)
      update(index,val,ipos,mid,pos*2);
      else
      update(index,val,mid+1,fpos,pos*2+1);
    }
  }
  ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
  {
    if(ipos>fpos)
    return 0;
    if(l>r)
    return 0;
    ll mid=(ipos+fpos)/2;
    if((l==ipos)&&(r==fpos))
    return v[pos];
    else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);
  }
};
struct BIT
{
vector<ll>bitree;ll n;
BIT(ll n)
{
this->n=n;
bitree.resize(n+1,0);
}
void update(ll idx,ll val)
{
  idx++;
  while(idx<=n)
  {
    bitree[idx]+=val;
    idx+=idx&(-idx);
  }
}
ll Sum(ll idx)
{
  ll sum=0;
  idx++;
  while(idx>0)
  {
    sum+=bitree[idx];
    idx-=idx&(-idx);
  }
  return sum;
}
};
ll sumofdigits(ll a)
{
  ll val=0;
  while(a>0)
  {
    val+=a%10;
    a/=10;
  }
  return val;
}

ll noOfDig(ll n){
  ll cnt=0;
  while(n){
    cnt++;n/=10;
  }
  return cnt;
}

vll arr;
ll n;
bool check(ll x){
  ll ans=0;
  rep(i, 0, n-1, 1){
    if(x<arr[i])return false;
    ans+=max(0ll, x-arr[i]);
  }
  if(ans>=x)return true;
  return false;
}

int main(){
  fastio;
  cin>>n;arr.resize(n);
  rep(i, 0, n-1, 1)cin>>arr[i];
  ll l=1, r=(ll)1e18;
  ll mid=0;
  while(l<r){
    // cout<<mid<<endl;
    mid=l+(r-l)/2;
    if(check(mid) and (mid==1 or !check(mid-1))) break;
    else if(check(mid))r=mid;
    else l=mid;
  }
  cout<<mid<<endl;
  return 0;
}


	#include<bits/stdc++.h>
	#define pb push_back
	#define ll unsigned long long
	#define pb push_back
	#define ff first
	#define ss second
	#define fast() ios_base::sync_with_stdio(0) ; cin.tie(0) ;
	#define endl '\n'
	const int mod = 1e9 + 7 ;
	using namespace std ;
	 int main(){
		 fast() ;
		 int n ;
		 cin>> n ;
		 vector<ll> a(n) ;
		 for(int i = 0 ; i < n ; ++i)
			cin>> a[i] ;
			long double sum = accumulate(a.begin() , a.end() , 0) ;

			long double ans  = *max_element(a.begin() , a.end()) ;

			  ans = max(ans , ceil(sum/(n-1))) ;
			  cout<<ans<<endl;
		  }


	#include<bits/stdc++.h>
	#define pb push_back
	#define ll unsigned long long
	#define pb push_back
	#define ff first
	#define ss second
	#define fast() ios_base::sync_with_stdio(0) ; cin.tie(0) ;
	#define endl '\n'
	const int mod = 1e9 + 7 ;
	using namespace std ;
	 int main(){
		 fast() ;
		 int n ;
		 cin>> n ;
		 vector<ll> a(n) ;
		 long double ans = 0 ;
		 for(int i = 0 ; i < n ; ++i){
			cin>> a[i] ;
			ans +=a[i] ;
		}
			long double sum = accumulate(a.begin() , a.end() , 0) ;

			// long double ans  = *max_element(a.begin() , a.end()) ;

			  ans = max(ans , ceil(sum/(n-1))) ;
			  cout<<ans<<endl;
		  }


	#include<bits/stdc++.h>
	#define pb push_back
	#define ll unsigned long long
	#define pb push_back
	#define ff first
	#define ss second
	#define fast() ios_base::sync_with_stdio(0) ; cin.tie(0) ;
	#define endl '\n'
	const int mod = 1e9 + 7 ;
	using namespace std ;
	 int main(){
		 fast() ;
		 int n ;
		 cin>> n ;
		 vector<ll> a(n) ;
		 long double sum = 0 ;
		 for(int i = 0 ; i < n ; ++i){
			cin>> a[i] ;
			sum+=a[i] ;
		}
			//long double sum = accumulate(a.begin() , a.end() , 0) ;

		 long double ans  = *max_element(a.begin() , a.end()) ;

			  ans = max(ans , ceil(sum/(n-1))) ;
			  cout<<ans<<endl;
		  }


#include<bits/stdc++.h>
#define pb push_back
#define ll unsigned long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
const int mod = 1e9 + 7 ;
using namespace std ;
 int main(){
	 int n ;
	 cin>> n ;
	 vector<int> a(n) ;
	 for(int i = 0 ; i < n ; ++i)
	    cin>> a[i] ;
	    ll sum = accumulate(a.begin() , a.end() , 0) ;
	    if(sum%(n - 1) == 0 )
	      cout<< sum/(n -1) <<endl;
	      else
	      cout<<sum/(n-1) + 1 <<endl;
	  }


	#include<bits/stdc++.h>
	#define pb push_back
	#define ll unsigned long long
	#define pb push_back
	#define ff first
	#define ss second
	#define fast() ios_base::sync_with_stdio(0) ; cin.tie(0) ;
	#define endl '\n'
	const int mod = 1e9 + 7 ;
	using namespace std ;
	 int main(){
		 fast() ;
		 int n ;
		 cin>> n ;
		 vector<ll > a(n) ;
		 ll sum = 0  , ans = 0 ;
		 for(int i = 0 ; i < n ; ++i){
			cin>> a[i] ;
			sum+=a[i] ;
			ans = max(ans , a[i]) ;
		}
			//long double sum = accumulate(a.begin() , a.end() , 0) ;

			  long double   x = (double)sum/(double )(n - 1) ;
			  ans = max(ans ,(ll) ceil(x)) ;
			  cout<<ans<<endl;
		  }


#include<bits/stdc++.h>
#define pb push_back
#define ll unsigned long long
#define pb push_back
#define ff first
#define ss second
#define fast() ios_base::sync_with_stdio(0) ; cin.tie(0) ;
#define endl '\n'
const int mod = 1e9 + 7 ;
using namespace std ;
 int main(){
	 fast() ;
	 int n ;
	 cin>> n ;
	 vector<int> a(n) ;
	 for(int i = 0 ; i < n ; ++i)
	    cin>> a[i] ;
	    double sum = accumulate(a.begin() , a.end() , 0) ;

	    double ans  = *max_element(a.begin() , a.end()) ;

	      ans = max(ans , ceil(sum/(n-1))) ;
	      cout<<ans<<endl;
	  }


	#include<bits/stdc++.h>
	#define pb push_back
	#define ll unsigned long long
	#define pb push_back
	#define ff first
	#define ss second
	#define fast() ios_base::sync_with_stdio(0) ; cin.tie(0) ;
	#define endl '\n'
	const int mod = 1e9 + 7 ;
	using namespace std ;
	 int main(){
		 fast() ;
		 int n ;
		 cin>> n ;
		 vector<long double > a(n) ;
		 long double sum = 0  , ans ;
		 for(int i = 0 ; i < n ; ++i){
			cin>> a[i] ;
			sum+=a[i] ;
			ans = max(ans , a[i]) ;
		}
			//long double sum = accumulate(a.begin() , a.end() , 0) ;

			  ans = max(ans , ceil(sum/(n-1))) ;
			  cout<<ans<<endl;
		  }


	#include<bits/stdc++.h>
	#define pb push_back
	#define ll unsigned long long
	#define pb push_back
	#define ff first
	#define ss second
	#define fast() ios_base::sync_with_stdio(0) ; cin.tie(0) ;
	#define endl '\n'
	const int mod = 1e9 + 7 ;
	using namespace std ;
	 int main(){
		 fast() ;
		 int n ;
		 cin>> n ;
		 vector<ll> a(n) ;
		 for(int i = 0 ; i < n ; ++i)
			cin>> a[i] ;
		long 	long double sum = accumulate(a.begin() , a.end() , 0) ;

			long long double ans  = *max_element(a.begin() , a.end()) ;

			  ans = max(ans , ceil(sum/(n-1))) ;
			  cout<<ans<<endl;
		  }


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    LLI m=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        arr[i]=temp;
        sum+=temp;
        m=max(m,arr[i]);
    }
    LLI result=-1;
    LLI start=m;
    LLI end=1000000000000;
    while(start<=end)
    {
        LLI mid=start+(start+end)/2;
        if(n*mid-sum>=mid)
        {
            result=mid;
            end=mid-1;
        }
        else
        {
            start=mid+1;
        }
    }
    cout<<result;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    LLI m=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        arr[i]=temp;
        sum+=temp;
        m=max(m,arr[i]);
    }
    LLI result=-1;
    LLI start=0;
    LLI end=1000000000000;
    while(start<=end)
    {
        LLI mid=(start+end)/2;
        if(n*mid-sum<=m)
        {
            start=mid+1;
        }
        else
        {
            result=mid;
            end=mid-1;
        }
    }
    cout<<result;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    LLI m=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        arr[i]=temp;
        sum+=temp;
        m=max(m,arr[i]);
    }
    LLI result=-1;
    LLI start=0;
    LLI end=1000000000000;
    while(start<=end)
    {
        LLI mid=(start+end)/2;
        if(n*mid-sum<m)
        {
            start=mid+1;
        }
        else
        {
            result=mid;
            end=mid-1;
        }
    }
    cout<<result;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    LLI m=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        arr[i]=temp;
        sum+=temp;
        m=max(m,arr[i]);
    }
    LLI result=-1;
    LLI start=0;
    LLI end=10000000000;
    while(start<=end)
    {
        LLI mid=(start+end)/2;
        if(n*mid-sum>=mid)
        {
            result=mid;
            end=mid-1;
        }
        else
        {
            start=mid+1;
        }
    }
    cout<<result;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        sum+=temp;
    }
    cout<<ceil((double)((double)sum/(double)(n-1)));
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    LLI m=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        arr[i]=temp;
        sum+=temp;
        m=max(m,arr[i]);
    }
    LLI result=-1;
    LLI start=0;
    LLI end=1000000000000;
    while(start<=end)
    {
        LLI mid=(start+end)/2;
        if(n*mid-sum>=mid)
        {
            result=mid;
            end=mid-1;
        }
        else
        {
            start=mid+1;
        }
    }
    cout<<result;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    LLI m=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        arr[i]=temp;
        sum+=temp;
        m=max(m,arr[i]);
    }
    LLI result=-1;
    LLI start=0;
    LLI end=1000000000000;
    while(start<=end)
    {
        LLI mid=(start+end)/2;
        if(n*mid-sum>=mid && mid>=m)
        {
            result=mid;
            end=mid-1;
        }
        else
        {
            start=mid+1;
        }
    }
    cout<<result;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#define LLI long long int
using namespace std;

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

    int n;
    cin>>n;
    LLI arr[n];
    LLI sum=0;
    LLI m=0;
    for(int i=0;i<n;i++)
    {
        LLI temp;
        cin >>temp;
        arr[i]=temp;
        sum+=temp;
        m=max(arr[i-1],arr[i]);
    }
    LLI result=-1;
    LLI start=0;
    LLI end=1000000000000;
    while(start<=end)
    {
        LLI mid=(start+end)/2;
        if(n*mid-sum>m)
        {
            result=mid;
            end=mid-1;
        }
        else
        {
            start=mid+1;
        }
    }
    cout<<result;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

bool solve(int n, int* a, long long val)
{
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		sum += val - a[i];
	}
	bool can = true;
	for(int i = 0; i < n; i++)
	{
		if(sum - (val - a[i]) < a[i])
			can = false;
	}
	return can;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	long long start = 1, end = 1e14 + 10;
	long long mid;
	long long sol = 0;
	while(start <= end)
	{
		mid = (start + end) / 2;
		bool can = solve(n, a, mid);
		if(can)
		{
			sol = mid;
			end = mid - 1;
		}
		else
		{
			start = mid + 1;
		}
	}
	cout << sol;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

bool solve(int n, long long* a, long long val)
{
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		sum += val - a[i];
	}
	bool can = true;
	for(int i = 0; i < n; i++)
	{

	}
	return can;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	int n;
	cin >> n;
	long long a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	long long start = a[n - 1], end = a[n - 1] + a[0];
	long long mid;
	long long sol = 0;
	while(start <= end)
	{
		mid = (start + end) / 2;
		bool can = solve(n, a, mid);
		if(can)
		{
			sol = mid;
			end = mid - 1;
		}
		else
		{
			start = mid + 1;
		}
	}
	cout << sol;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	int n;
	cin >> n;
	int a[n];
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	long long sol = (sum + n - 2) / (n - 1);
	sol = max(sol, (long long)a[n - 1]);
	cout << sol;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

bool solve(int n, int* a, long long val)
{
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		sum += val - a[i];
	}
	bool can = true;
	for(int i = 0; i < n; i++)
	{
		if(sum - (val - a[i]) < a[i])
			can = false;
	}
	return can;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	long long start = 1, end = 1e18;
	long long mid;
	long long sol = 0;
	while(start <= end)
	{
		mid = (start + end) / 2;
		bool can = solve(n, a, mid);
		if(can)
		{
			sol = mid;
			end = mid - 1;
		}
		else
		{
			start = mid + 1;
		}
	}
	cout << sol;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	int n;
	cin >> n;
	int a[n];
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	long long sol = (sum + n - 2) / (n - 1);
	sol = max(sol, (long long)*max_element(a, a + n));
	cout << sol;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

bool solve(int n, long long* a, long long val)
{
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		sum += val - a[i];
	}
	bool can = true;
	for(int i = 0; i < n; i++)
	{
		if(sum - (val - a[i]) < a[i])
			can = false;
	}
	return can;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);

	int n;
	cin >> n;
	long long a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	long long start = a[n - 1], end = a[n - 1] + a[0];
	long long mid;
	long long sol = 0;
	while(start <= end)
	{
		mid = (start + end) / 2;
		bool can = solve(n, a, mid);
		if(can)
		{
			sol = mid;
			end = mid - 1;
		}
		else
		{
			start = mid + 1;
		}
	}
	cout << sol;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,s=0,ans=INT_MIN;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>a;
        s+=a;
        ans=max(ans,a);
    }
    ll val=1+floor(s/(n-1));
    val=max(val,ans);
    cout<<val<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,ans=0;
    scanf("%lld",&n);
    for(ll i=0;i<n;i++)
    {
        scanf("%lld",&a);
        ans=max(a,ans);
    }
    printf("%lld\n",ans+1);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,ans2=INT_MAX,ans1=INT_MIN;
    scanf("%lld",&n);
    for(ll i=0;i<n;i++)
    {
        scanf("%lld",&a);
        ans1=max(a,ans1);
        ans2=min(ans2,a);
    }
    printf("%lld\n",ans2+1>=ans1?ans1+1:ans1);
}


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

int main() {
    long long int n, a, ma=0, cnt=0;
    scanf("%I64d", &n);
    for(int i=0; i<n; i++) {
        scanf("%I64d", &a);
        if(a>ma) ma=a;
        cnt+=a;
    }
    a=ceil((double)cnt/(n-1)), a=max(a, ma);
    printf("%I64d", a);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,s=0;
    scanf("%lld",&n);
    for(ll i=0;i<n;i++)
    {
        scanf("%lld",&a);
        s+=a;
    }
    ll val=1+floor(s/(n-1));
    printf("%lld\n",val);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,s=0,ans=INT_MIN;
    scanf("%lld",&n);
    for(ll i=0;i<n;i++)
    {
        scanf("%lld",&a);
        s+=a;
        ans=max(ans,a);
    }
    ll val=1+floor(s/(n-1));
    if(val<ans)
        val=ans;
    printf("%lld\n",val);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,s=0,ans=INT_MIN;
    scanf("%lld",&n);
    for(ll i=0;i<n;i++)
    {
        scanf("%lld",&a);
        s+=a;
        ans=max(ans,a);
    }
    ll val=ceil(s/(n-1));
    if(val<ans)
        val=ans;
    printf("%lld\n",val);
}


/*
    ॐ नमः शिवाय
                    */

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define MAX 100005
#define pi 2 * acos(0.0)
using namespace std;

#define vect vector<int>
#define vectp vector<pair<int,int>>
#define matrix vector<vector<int>>
#define mp make_pair
#define pb(i) push_back(i)
#define lb lower_bound
#define ub upper_bound
#define geti(n) int n; cin >> n;
#define gets(str) string str; cin >> str;
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop(i,j,k) for(int i = j; i >= k; i--)
#define test  int t;  cin >> t; while (t--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

/* YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY */

signed main()
{
    fastio;

    geti(n);
    int sum = 0;
    loop(i,0,n)
    {
       geti(temp);
       sum += temp;
    }

    int val = ceil((float)sum/(n - 1));

    cout<< min(val,sum);

    return 0;
}


/*
    ॐ नमः शिवाय
                    */

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define sz 1000005
#define MAX 100005
#define pi 2 * acos(0.0)
using namespace std;

#define vect vector<int>
#define vectp vector<pair<int, int>>
#define matrix vector<vector<int>>
#define mp make_pair
#define pb(i) push_back(i)
#define lb lower_bound
#define ub upper_bound
#define geti(n) \
    int n;      \
    cin >> n
#define gets(str) \
    string str;   \
    cin >> str;
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

/* YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY */

signed main()
{
    fastio;

    geti(n);
    vect v(n);
    bool con = true;
    int val = -1;
    loop(i, 0, n)
    {
        cin >> v[i];
        if (i == 0)
            val = v[i];
        else
        {
            if (v[i] != v[i - 1])
                con = false;
        }
    }

    if (con)
    {
        if (val < n)
            cout << val + 1;
        else
        {
            int b = (val / (n - 1)) * n;
            if (val % n)
                b += (val % (n - 1)) + 1;
            cout << b;
        }
        return 0;
    }
    sort(v.begin(), v.end());

    if (v[0] == v[1] && v[1] == v[2])
        cout << v[n - 1];
    else if (v[0] == v[1])
        cout << max(2 * v[0], v[n - 1]);
    else
    {
        int g = v[1] - v[0];
        int ans = g + max(2 * v[0], v[n - 1] - g);
        cout << ans;
    }

    return 0;
}


/*
    ॐ नमः शिवाय
                    */

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define sz 1000005
#define MAX 100005
#define pi 2 * acos(0.0)
using namespace std;

#define vect vector<int>
#define vectp vector<pair<int, int>>
#define matrix vector<vector<int>>
#define mp make_pair
#define pb(i) push_back(i)
#define lb lower_bound
#define ub upper_bound
#define geti(n) \
    int n;      \
    cin >> n
#define gets(str) \
    string str;   \
    cin >> str;
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

/* YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY */

signed main()
{
    fastio;

    geti(n);
    int sum = 0, maxv = INT_MIN;

    loop(i, 0, n)
    {
        geti(a);
        sum += a;
        maxv = max(a, maxv);
    }

    int ans = ceil((double)sum / (n - 1));

    cout << max(ans, maxv);

    return 0;
}


/*
    ॐ नमः शिवाय
                    */

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define MAX 100005
#define pi 2 * acos(0.0)
using namespace std;

#define vect vector<int>
#define vectp vector<pair<int,int>>
#define matrix vector<vector<int>>
#define mp make_pair
#define pb(i) push_back(i)
#define lb lower_bound
#define ub upper_bound
#define geti(n) int n; cin >> n;
#define gets(str) string str; cin >> str;
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop(i,j,k) for(int i = j; i >= k; i--)
#define test  int t;  cin >> t; while (t--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

/* YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY */

signed main()
{
    fastio;

    geti(n);
    vect v(n);

    int sum = 0;
    loop(i,0,n)
    {
        cin >> v[i];
        sum += v[i];
    }

    sort(v.begin(),v.end());

    int val = ceil((float)sum/(n-1));
    int ans = max(val,v[n-1]);

    cout << ans;

    return 0;
}


/*
    ॐ नमः शिवाय
                    */

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define sz 1000005
#define MAX 100005
#define pi 2 * acos(0.0)
using namespace std;

#define vect vector<int>
#define vectp vector<pair<int, int>>
#define matrix vector<vector<int>>
#define mp make_pair
#define pb(i) push_back(i)
#define lb lower_bound
#define ub upper_bound
#define geti(n) \
    int n;      \
    cin >> n
#define gets(str) \
    string str;   \
    cin >> str;
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

/* YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY */

signed main()
{
    fastio;

    geti(n);
    int sum = 0, maxv = INT_MIN;

    loop(i, 0, n)
    {
        geti(a);
        sum += a;
        maxv = max(a, maxv);
    }

    int ans = ceil((float)sum / (n - 1));

    cout << min(ans, maxv);
    return 0;
}


/*
    ॐ नमः शिवाय
                    */

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define sz 1000005
#define MAX 100005
#define pi 2 * acos(0.0)
using namespace std;

#define vect vector<int>
#define vectp vector<pair<int, int>>
#define matrix vector<vector<int>>
#define mp make_pair
#define pb(i) push_back(i)
#define lb lower_bound
#define ub upper_bound
#define geti(n) \
    int n;      \
    cin >> n
#define gets(str) \
    string str;   \
    cin >> str;
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

/* YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY */

signed main()
{
    fastio;

    geti(n);
    int sum = 0, maxv = INT_MIN;

    loop(i, 0, n)
    {
        geti(a);
        sum += a;
        maxv = max(a, maxv);
    }

    int ans = ceil((float)sum / (n - 1));

    if (ans < maxv)
        cout << maxv;
    else
        cout << ans;

    return 0;
}


/*
    ॐ नमः शिवाय
                    */

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define sz 1000005
#define MAX 100005
#define pi 2 * acos(0.0)
using namespace std;

#define vect vector<int>
#define vectp vector<pair<int, int>>
#define matrix vector<vector<int>>
#define mp make_pair
#define pb(i) push_back(i)
#define lb lower_bound
#define ub upper_bound
#define geti(n) \
    int n;      \
    cin >> n
#define gets(str) \
    string str;   \
    cin >> str;
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

/* YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY */

signed main()
{
    fastio;

    geti(n);
    vect v(n);
    bool con = true;
    int val = -1;
    loop(i, 0, n)
    {
        cin >> v[i];
        if (i == 0)
            val = v[i];
        else
        {
            if (v[i] != v[i - 1])
                con = false;
        }
    }

    if (con)
    {
        if (val < n)
            cout << val + 1;
        else
        {
            int b = (val / (n - 1)) * n;
            if (val % n)
                b += (val % (n - 1)) + 1;
            cout << b;
        }
        return 0;
    }
    sort(v.begin(), v.end());
    int g = v[1] - v[0];
    int maxv = v[n - 1] - v[1] + v[0];
    int ans = g + max(2 * v[0], maxv);
    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'

int main(){
	IoFast;
	int n;
	cin >> n;
	ll sum = 0, mn = 1e9 + 7, mx = 0;
	foor(i, 0, n){
		int x;
		cin >> x;
		sum += x;
		//if (x < mn)
		//	mn = x;
		if (x > mx)
			mx = x;
	}
	ll ans = max((sum + n - 2) / (n - 1), mx) ;

	//while (ar[n - 1] > 0){
	//	foor(i, 1, n)
	//		ar[i]--;
	//	sort(ar, ar + n);
	//	ans ++;
	//}
	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'

int main(){
	IoFast;
	int n;
	cin >> n;
	int ar[n];
	fillArr(n, ar);
	sort(ar, ar + n);
	int ans = 0;
	while (ar[n - 1] > 0){
		foor(i, 1, n)
			ar[i]--;
		sort(ar, ar + n);
		ans ++;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'

int main(){
	IoFast;
	int n;
	cin >> n;
	int ar[n];
	fillArr(n, ar);
	sort(ar, ar + n);
	ll ans = ar[0] + ar[1] - 1;
	//while (ar[n - 1] > 0){
	//	foor(i, 1, n)
	//		ar[i]--;
	//	sort(ar, ar + n);
	//	ans ++;
	//}
	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'

int main(){
	IoFast;
	int n;
	cin >> n;
	ll sum = 0;
	foor(i, 0, n){
		int x;
		cin >> x;
		sum += x;
	}
	ll ans = (sum + n - 2) / (n - 1);
	//while (ar[n - 1] > 0){
	//	foor(i, 1, n)
	//		ar[i]--;
	//	sort(ar, ar + n);
	//	ans ++;
	//}
	cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    long long n, sum = 0, mx = 0, x, ans;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        if(x > mx)
            mx = x;
        sum += x;
    }
    ans = max(mx, (sum + n - 2) / (n - 1));
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'

int main(){
	IoFast;
	int n;
	cin >> n;
	ll sum = 0, mn = 1e9 + 7, mx = 0;
	foor(i, 0, n){
		int x;
		cin >> x;
		sum += x;
		if (x < mn)
			mn = x;
		if (x > mx)
			mx = x;
	}
	ll ans = max((sum + n - 2) / (n - 1), mn + mx) ;
	//while (ar[n - 1] > 0){
	//	foor(i, 1, n)
	//		ar[i]--;
	//	sort(ar, ar + n);
	//	ans ++;
	//}
	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'

int main(){
	IoFast;
	int n;
	cin >> n;
	int ar[n];
	fillArr(n, ar);
	sort(ar, ar + n);
	ll ans = (ar[0] + 1) / 2 + ar[n - 1];
	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int sum=0;
long long int arr[100005];
bool check(long long int md)
{
    if(md*(n-1)>=sum)return 1;
    return 0;
}
int main()
{
    cin>>n;
    long long int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        arr[i]=x;
        sum+=x;
    }
    sort(arr+1,arr+n+1);
    long long int st=arr[n],nd=arr[n]*2,ans=0,md;
    while(st<=nd)
    {
        md=st+(nd-st)/2;
        if(check(md))
        {
            ans=md;
            nd=md-1;
        }
        else
        {
            st=md+1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        long long int k,sum=0;
        for(int i=0;i<n;i++)
        {
            cin>>k;
            sum+=k;
        }
        if(n==3)
        {
            cout<<round((sum+0.9)/(n-1));
        }
        else
        {
            cout<<round((sum+1)*1.0/(n-1));
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int sum=0;
long long int arr[100005];
bool check(long long int md)
{
    if(md*(n-1)>=sum)return 1;
    return 0;
}
int main()
{
    cin>>n;
    long long int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        arr[i]=x;
        sum+=x;
    }
    sort(arr+1,arr+n+1);
    int st=0,nd=arr[n]*2,ans=0,md;
    while(st<=nd)
    {
        md=st+(nd-st)/2;
        if(check(md))
        {
            ans=md;
            nd=md-1;
        }
        else
        {
            st=md+1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    long long int k,sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        sum+=k;
    }
    if(sum%(n-1)!=0)
    {
        sum+=1;
        cout<<ceil((sum)*1.0/(n-1));
    }
    else
    {
        cout<<round((sum)*1.0/(n-1));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int sum=0;
long long int arr[100005];
bool check(long long int md)
{
    if(md*(n-1)>=sum)return 1;
    return 0;
}
int main()
{
    cin>>n;
    long long int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        arr[i]=x;
        sum+=x;
    }
    sort(arr+1,arr+n+1);
    long long int st=arr[n],nd=arr[n]*10,ans=0,md;
    while(st<=nd)
    {
        md=st+(nd-st)/2;
        if(check(md))
        {
            ans=md;
            nd=md-1;
        }
        else
        {
            st=md+1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int sum=0;
long long int arr[100005];
bool check(long long int md)
{
    if(md*(n-1)>=sum)return 1;
    return 0;
}
int main()
{
    cin>>n;
    long long int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        arr[i]=x;
        sum+=x;
    }
    sort(arr+1,arr+n+1);
    long long int st=1,nd=arr[n]*4,ans=0,md;
    while(st<=nd)
    {
        md=st+(nd-st)/2;
        if(check(md))
        {
            ans=md;
            nd=md-1;
        }
        else
        {
            st=md+1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int sum=0;
long long int arr[100005];
bool check(long long int md)
{
    if(md*(n-1)>=sum)return 1;
    return 0;
}
int main()
{
    cin>>n;
    long long int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        arr[i]=x;
        sum+=x;
    }
    sort(arr+1,arr+n+1);
    long long int st=arr[n],nd=arr[n]*n,ans=0,md;
    while(st<=nd)
    {
        md=st+(nd-st)/2;
        if(check(md))
        {
            ans=md;
            nd=md-1;
        }
        else
        {
            st=md+1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    long long int k,sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        sum+=k;
    }
    if(n==3)
    {
        cout<<round((sum+0.9)/(n-1));
    }
    else
    {
        cout<<round((sum+1)*1.0/(n-1));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    long long int k,sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        sum+=k;
    }
    if(sum%(n-1)!=0)
    {
        sum+=1;
        cout<<ceil((sum)*1.0/(n-1));
    }
    else
    {
        cout<<ceil((sum)*1.0/(n-1));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int sum=0;
long long int arr[100005];
bool check(long long int md)
{
    if(md*(n-1)>=sum)return 1;
    return 0;
}
int main()
{
    cin>>n;
    long long int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        arr[i]=x;
        sum+=x;
    }
    sort(arr+1,arr+n+1);
    int md=arr[n]*2,ans=0;
    while(md>=0)
    {
        if(check(md))
        {
            ans=md;
            md-=1;
        }
        else
        {
            break;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int sum=0;
long long int arr[100005];
bool check(long long int md)
{
    if(md*(n-1)>=sum)return 1;
    return 0;
}
int main()
{
    cin>>n;
    long long int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        arr[i]=x;
        sum+=x;
    }
    sort(arr+1,arr+n+1);
    long long int st=0,nd=arr[n]*4,ans=0,md;
    while(st<=nd)
    {
        md=st+(nd-st)/2;
        if(check(md))
        {
            ans=md;
            nd=md-1;
        }
        else
        {
            st=md+1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin>>t;
    int n;cin>>n;
    long long int k,sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        sum+=k;
    }
    if(n==3)
    {
        cout<<round((sum+0.9)/(n-1));
    }
    else
    {
        cout<<round((sum+1)*1.0/(n-1));
    }
    return 0;
}


/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e10;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

ll bs(ll l,ll r,ll n,ll sum) {
    ll ans=0ll;
    while(l<=r) {
        ll mid=(l+r)>>1ll;
        ll d=n*mid-sum;
        if(mid<=d) {
            r=mid-1ll;
            ans=mid;
        } else {
            l=mid+1ll;
        }
    }
    return ans;
}
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n,sum=0ll,mx=0ll;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            ll x;
            cin>>x;
            mx=max(mx,x);
            sum+=x;
        }
        cout<<bs(mx,inf,n,sum)<<el;
    }
    return 0;
}


/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e18;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

ll bs(ll l,ll r,ll n,ll sum) {
    ll ans=0ll;
    while(l<=r) {
        ll mid=(l+r)>>1ll;
        ll d=n*mid-sum;
        if(d>=mid) {
            r=mid-1ll;
            ans=mid;
        } else {
            l=mid+1ll;
        }
    }
    return ans;
}
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n,sum=0ll;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            ll x;
            cin>>x;
            sum+=x;
        }
        cout<<bs(0ll,(ll)1e10,n,sum);
    }
    return 0;
}


/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e18;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

map<int,int>mp;
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        int n,mx=0;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            int x;
            cin>>x;
            ++mp[x];
            //cout<<mp[x]<<" ";
            mx=max(mx,x);
        }
        if(mx<n) {
            cout<<mx+1<<el;
        } else {
            int tv=mp[mx];
            mx-=(mp[mx]/2);//cout<<mx<<" ";
            cout<<mx+tv<<el;
        }
    }
    return 0;
}


/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e18;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

ll bs(ll l,ll r,ll n,ll sum) {
    ll ans=0ll;
    while(l<=r) {
        ll mid=(l+r)>>1ll;
        ll d=n*mid-sum;
        if(d>=mid) {
            r=mid-1ll;
            ans=mid;
        } else {
            l=mid+1ll;
        }
    }
}
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n,sum=0ll;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            ll x;
            cin>>x;
            sum+=x;
        }
        cout<<bs(0ll,(ll)1e10,n,sum);
    }
    return 0;
}


/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e10;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

ll bs(ll l,ll r,ll n,ll sum) {
    ll ans=0ll;
    while(l<=r) {
        ll mid=(l+r)>>1ll;
        ll d=n*mid-sum;
        if(mid<=d) {
            r=mid-1ll;
            ans=mid;
        } else {
            l=mid+1ll;
        }
    }
    return ans;
}
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n,sum=0ll;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            ll x;
            cin>>x;
            sum+=x;
        }
        cout<<bs(0ll,inf,n,sum)<<el;
    }
    return 0;
}


/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e18;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

map<ll,ll>mp;
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n,mx=0ll;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            ll x;
            cin>>x;
            ++mp[x];
            //cout<<mp[x]<<" ";
            mx=max(mx,x);
        }
        if(mx<n) {
            cout<<mx+1ll<<el;
        } else {
            ll tv=mp[mx];
            mx-=(mp[mx]>>1ll);//cout<<mx<<" ";
            cout<<mx+tv<<el;
        }
    }
    return 0;
}


/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define grv(v) sort(v.begin(),v.end(),greater<int>())
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define el "\n"
#define IOS  ios_base::sync_with_stdio(false),cin.tie(NULL)

const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const ll inf=(ll)1e18;
const double pi=2*acos(0.0);
const double esp=1e-9;

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

ll bs(ll l,ll r,ll n,ll sum) {
    ll ans;
    while(l<=r) {
        ll mid=(l+r)>>1ll;
        ll d=n*mid-sum;
        if(d>=mid) {
            r=mid-1ll;
            ans=mid;
        } else {
            l=mid+1ll;
        }
    }
}
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n,sum=0ll;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            ll x;
            cin>>x;
            sum+=x;
        }
        cout<<bs(0ll,inf,n,sum);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn = 5e5;

int n;
int a[maxn];

int ans;

int f(int x){
  for (int i = 1; i <= n; i++){
    if(max(0 * 1ll,x - a[i]) <= x)
      return 0;
  }
  return 1;
}

main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++ ){
    cin >> a[i];
  }
  int lf = 0;
  int rg = maxn;
  while(rg - lf > 1){
    int mid = (rg + lf) / 2;
    if(f(mid))
      rg = mid;
    else
      lf = mid;
  }
  if ( f(lf) )
    ans = lf;
  else
    ans = rg;
  cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn = 5e5;

int n;
int a[maxn];
int sum;
int ans;

int summ;

int f(int x){
  sum = 0;
  for (int i = 1; i <= n; i++){
      sum += max(0 * 1ll,x - a[i]);
  }
  if(sum >= x)
    return 1;
  return 0;
}

main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++ ){
    cin >> a[i];
    summ += a[i];
  }
  int lf = *max_element(a + 1, a + 1 + n);
  int rg = summ;
  while(rg - lf > 1){
    int mid = (rg + lf) / 2;
    if(f(mid))
      rg = mid;
    else
      lf = mid;
  }
  if ( f(lf) )
    ans = lf;
  else
    ans = rg;
  cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn = 5e5;

int n;
int a[maxn];

int ans;

int f(int x){
  for (int i = 1; i <= n; i++){
    if(max(0 * 1ll,x - a[i]) <= 0)
      return 0;
  }
  return 1;
}

main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++ ){
    cin >> a[i];
  }
  int lf = 0;
  int rg = maxn;
  while(rg - lf > 1){
    int mid = (rg + lf) / 2;
    if(f(mid))
      rg = mid;
    else
      lf = mid;
  }
  if ( f(lf) )
    ans = lf;
  else
    ans = rg;
  cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn = 5e5;

int n;
int a[maxn];

int ans;

int f(int x){
  for (int i = 1; i <= n; i++){
    if(max(0 * 1ll,x - a[i]) < x)
      return 0;
  }
  return 1;
}

main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++ ){
    cin >> a[i];
  }
  int lf = 0;
  int rg = maxn;
  while(rg - lf > 1){
    int mid = (rg + lf) / 2;
    if(f(mid))
      rg = mid;
    else
      lf = mid;
  }
  if ( f(lf) )
    ans = lf;
  else
    ans = rg;
  cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn = 5e5;

int n;
int a[maxn];
int sum;
int ans;

int f(int x){
  sum = 0;
  for (int i = 1; i <= n; i++){
      sum += max(0 * 1ll,x - a[i]);
  }
  if(sum >= x)
    return 1;
  return 0;
}

main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++ ){
    cin >> a[i];
  }
  int lf = 0;
  int rg = maxn;
  while(rg - lf > 1){
    int mid = (rg + lf) / 2;
    if(f(mid))
      rg = mid;
    else
      lf = mid;
  }
  if ( f(lf) )
    ans = lf;
  else
    ans = rg;
  cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn = 5e5;

int n;
int a[maxn];

int ans;

int f(int x){
  for (int i = 1; i <= n; i++){
    if(max(0 * 1ll,x - a[i]) < 0)
      return 0;
  }
  return 1;
}

main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++ ){
    cin >> a[i];
  }
  int lf = 0;
  int rg = maxn;
  while(rg - lf > 1){
    int mid = (rg + lf) / 2;
    if(f(mid))
      rg = mid;
    else
      lf = mid;
  }
  if ( f(lf) )
    ans = lf;
  else
    ans = rg;
  cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn = 5e5;

int n;
int a[maxn];
int sum;
int ans;

int f(int x){
  sum = 0;
  for (int i = 1; i <= n; i++){
      sum += max(0 * 1ll,x - a[i]);
  }
  if(sum >= x)
    return 1;
  return 0;
}

main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++ ){
    cin >> a[i];
  }
  int lf = *max_element(a + 1, a + 1 + n);
  int rg = maxn;
  while(rg - lf > 1){
    int mid = (rg + lf) / 2;
    if(f(mid))
      rg = mid;
    else
      lf = mid;
  }
  if ( f(lf) )
    ans = lf;
  else
    ans = rg;
  cout << ans;
}


#include <bits/stdc++.h>

#define Pi acos(-1.)
#define pb push_back
#define mp make_pair
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;
const ll LINF = 1e15;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll a[MAXN], n, ans = LINF;

bool ok(ll tot)
{
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        x += tot - a[i];
        if(a[i] > tot)
            return false;
    }
    return (x >= tot);
}

void solve()
{
    cin >> n;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ll l = 1, r = LINF;
    while(l < r)
    {
        ll mid = (l + r) >> 1;
        if(ok(mid))
        {
            r = mid;
        }
        else
            l = mid + 1;
    }
    cout << l;

}

int main()
{
    if(!standart)
    {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>

#define Pi acos(-1.)
#define pb push_back
#define mp make_pair
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;
const ll LINF = 1e15;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll a[MAXN], n, ans = LINF;

bool ok(ll tot)
{
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        x += tot - a[i];
        if(a[i] > tot)
            return false;
    }
    return (x >= tot);
}

void solve()
{
    cin >> n;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ll l = 1, r = LINF;
    while(l <= r)
    {
        ll mid = (l + r) >> 1;
        if(ok(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout << ans;

}

int main()
{
    if(!standart)
    {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>

#define Pi acos(-1.)
#define pb push_back
#define mp make_pair
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;
const ll LINF = 1e18;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll a[MAXN], n, ans = LINF;

bool ok(ll tot)
{
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        x += tot - a[i];
    }
    return (x >= tot);
}

void solve()
{
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    ll l = 1, r = LINF;
    while(l <= r)
    {
        ll mid = (l + r) >> 1;
        if(ok(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout << ans;

}

int main()
{
    if(!standart)
    {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>

#define Pi acos(-1.)
#define pb push_back
#define mp make_pair
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;
const ll LINF = 1e15;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll a[MAXN], n, ans = LINF;

bool ok(ll tot)
{
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        x += tot - a[i];
    }
    return (x >= tot);
}

void solve()
{
    cin >> n;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ll l = mx, r = LINF;
    while(l <= r)
    {
        ll mid = (l + r) >> 1;
        if(ok(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout << ans;

}

int main()
{
    if(!standart)
    {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>

#define Pi acos(-1.)
#define pb push_back
#define mp make_pair
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;
const ll LINF = 1e15;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll a[MAXN], n, ans = LINF;

bool ok(ll tot)
{
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        x += tot - a[i];
    }
    return (x >= tot);
}

void solve()
{
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    ll l = 1, r = LINF;
    while(l <= r)
    {
        ll mid = (l + r) >> 1;
        if(ok(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout << ans;

}

int main()
{
    if(!standart)
    {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>

#define Pi acos(-1.)
#define pb push_back
#define mp make_pair
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;
const ll LINF = 1e12;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll a[MAXN], n, ans = LINF;

bool ok(ll tot)
{
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        x += tot - a[i];
        if(a[i] > tot)
            return false;
    }
    return (x >= tot);
}

void solve()
{
    cin >> n;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ll l = 1, r = LINF;
    while(l <= r)
    {
        ll mid = (l + r) >> 1;
        if(ok(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout << ans;

}

int main()
{
    if(!standart)
    {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>

#define Pi acos(-1.)
#define pb push_back
#define mp make_pair
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;
const ll LINF = 1e15;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-14;

ll a[MAXN], n, ans;

bool ok(ll tot)
{
    ll x = 0;
    for(int i = 0; i < n; i++)
    {
        x += tot - a[i];
    }
    return (x >= tot);
}

void solve()
{
    cin >> n;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ll l = mx, r = LINF;
    ans = mx;
    while(l <= r)
    {
        ll mid = (l + r) >> 1;
        if(ok(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout << ans;

}

int main()
{
    if(!standart)
    {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();

    return 0;
}


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

char s[1000+100][1000+100];
bool vis[1000+10][1000+10];
int n,m,k,ans=0;
void dfs(int x , int y)
{
    if(vis[x][y])return;
    vis[x][y]=1;
    if(s[x][y]=='*')
    {
        ans++;
        return;
    }
                 dfs(x-1,y);
    dfs(x  ,y-1);           dfs(x  ,y+1);
                 dfs(x+1,y);
}

int main(void)
{
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
        cin>>s[i][j];
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        memset(vis,0,sizeof vis);
        ans=0;
        dfs(x,y);
        cout<<ans<<"\n";
    }
    return 0;
}


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

char s[1000+100][1000+100];
bool vis[1000+10][1000+10][10];
int n,m,k,ans=0;
void dfs(int x , int y , int d)
{
    if(vis[x][y][0])return;
    if(s[x][y]=='*')
    {
        if(vis[x][y][d])return;
        else
        {
            vis[x][y][d]=1;
            ans++;
            return;
        }
    }
    else vis[x][y][0]=1;
                 dfs(x-1,y,1);
    dfs(x,y-1,2);             dfs(x,y+1,3);
                 dfs(x+1,y,4);
}

int main(void)
{
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
        cin>>s[i][j];
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        memset(vis,0,sizeof vis);
        ans=0;
        dfs(x,y,0);
        cout<<ans<<"\n";
    }
    return 0;
}


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

char s[1000+100][1000+100];
bool vis[1000+10][1000+10];
int n,m,k,ans=0;
void dfs(int x , int y )
{
    //cout<<"dfs:"<<x<<" "<<y<<"\n";
    //system("pause");
    if(vis[x][y])return;
    if(s[x][y]=='*')
    {
        ans++;
        return;
    }
    else vis[x][y]=1;
                 dfs(x-1,y);
    dfs(x,y-1);             dfs(x,y+1);
                 dfs(x+1,y);
}

int main(void)
{
    //cin.tie(0);ios::sync_with_stdio(0);
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
        cin>>s[i][j];
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        if(vis[x][y])
        {
            cout<<ans<<"\n";
            continue;
        }
        memset(vis,0,sizeof vis);
        ans=0;
        dfs(x,y);
        cout<<ans<<"\n";
    }
    return 0;
}


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

char s[1000+100][1000+100];
bool vis[1000+10][1000+10];
int res[1000+10][1000+10]={0};
int n,m,k,ans=0;
void dfs(int x , int y )
{
    //cout<<"dfs:"<<x<<" "<<y<<"\n";
    //system("pause");
    if(vis[x][y])return;
    if(s[x][y]=='*')
    {
        ans++;
        return;
    }
    else vis[x][y]=1;
                 dfs(x-1,y);
    dfs(x,y-1);             dfs(x,y+1);
                 dfs(x+1,y);
}

int main(void)
{
    //cin.tie(0);ios::sync_with_stdio(0);
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
        cin>>s[i][j];
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        if(res[x][y])
        {
            cout<<res[x][y];
            continue;
        }
        memset(vis,0,sizeof vis);
        ans=0;
        dfs(x,y);
        cout<<ans<<"\n";
        for(int i=1 ; i<=n ; ++i)//save the answer
        for(int j=1 ; j<=m ; ++j)
        if(vis[i][j])res[i][j]=ans;
    }
    return 0;
}


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

char s[1000+100][1000+100];
int vis[1000+10][1000+10],ans[1000000+100]={0};
int n,m,k,v=0,t=0;
void dfs(int x , int y )
{
    //cout<<"dfs:"<<x<<" "<<y<<"\n";
    //system("pause");
    if(vis[x][y])return;
    if(s[x][y]=='*')
    {
        v++;
        return;
    }
    else vis[x][y]=t;
                 dfs(x-1,y);
    dfs(x,y-1);             dfs(x,y+1);
                 dfs(x+1,y);
}

int main(void)
{
    cin.tie(0);ios::sync_with_stdio(0);
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
        cin>>s[i][j];
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
    if(s[i][j]=='.')
    {
        t++;
        v=0;
        dfs(i,j);
        ans[t]=v;
    }
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        cout<<ans[vis[x][y]]<<"\n";
    }
    return 0;
}


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

char s[1000+100][1000+100];
bool vis[1000+10][1000+10];
int res[1000+10][1000+10]={0};
int n,m,k,ans=0;
void dfs(int x , int y )
{
    //cout<<"dfs:"<<x<<" "<<y<<"\n";
    //system("pause");
    if(vis[x][y])return;
    if(s[x][y]=='*')
    {
        ans++;
        return;
    }
    else vis[x][y]=1;
                 dfs(x-1,y);
    dfs(x,y-1);             dfs(x,y+1);
                 dfs(x+1,y);
}

int main(void)
{
    cin.tie(0);ios::sync_with_stdio(0);
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
        cin>>s[i][j];
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        if(res[x][y])
        {
            cout<<res[x][y]<<"\n";
            continue;
        }
        memset(vis,0,sizeof vis);
        ans=0;
        dfs(x,y);
        cout<<ans<<"\n";
        for(int i=1 ; i<=n ; ++i)//save the answer
        for(int j=1 ; j<=m ; ++j)
        if(vis[i][j])res[i][j]=ans;
    }
    return 0;
}


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

char s[1000+100][1000+100];
bool vis[1000+10][1000+10][10];
int n,m,k,ans=0;
void dfs(int x , int y , int d)
{
    if(vis[x][y][0])return;
    if(s[x][y]=='*')
    {
        if(vis[x][y][d])return;
        else
        {
            vis[x][y][d]=1;
            ans++;
            return;
        }
    }
    else vis[x][y][0]=1;
                 dfs(x-1,y,1);
    dfs(x,y-1,2);             dfs(x,y+1,3);
                 dfs(x+1,y,4);
}

int main(void)
{
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; ++i)
    for(int j=1 ; j<=m ; ++j)
        cin>>s[i][j];
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        if(vis[x][y][0])
        {
            cout<<ans<<"\n";
            continue;
        }
        memset(vis,0,sizeof vis);
        ans=0;
        dfs(x,y,0);
        cout<<ans<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[100001] = {};
int n, m, k, x, y, ans, i, j;
void visit(int x, int y){
    if (x == 0 || y == 0 || x == n + 1 || y == m + 1) return;
    if (c[x][y] == '*') { ans++; return; }
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x + 1, y);
    visit(x, y + 1);
    visit(x - 1, y);
    visit(x, y - 1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            scanf("%c",&(c[i][j]));
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        printf("%d\n",ans );
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[100001] = {};
int n, m, k, x, y, ans, i, j;
void visit(int x, int y){
    if (x == 0 || y == 0 || x == n + 1 || y == m + 1) return;
    if (c[x][y] == '*') { ans++; return; }
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x + 1, y);
    visit(x, y + 1);
    visit(x - 1, y);
    visit(x, y - 1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            scanf("%c",&(c[i][j]);
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        printf("%d\n",ans );
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[100001] = {};
int n, m, k, x, y, ans, i, j;
void visit(int x, int y){
    if (x == 0 || y == 0 || x == n + 1 || y == m + 1) return;
    if (c[x][y] == '*') { ans++; return; }
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x + 1, y);
    visit(x, y + 1);
    visit(x - 1, y);
    visit(x, y - 1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            scanf("%c",&c[i][j]);
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        printf("%d\n",ans );
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[100001] = {};
int n, m, k, x, y, ans, i, j;
void visit(int x, int y){
    if (x == 0 || y == 0 || x == n + 1 || y == m + 1) return;
    if (c[x][y] == '*') { ans++; return; }
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x + 1, y);
    visit(x, y + 1);
    visit(x - 1, y);
    visit(x, y - 1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            cin >> c[i][j];
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        printf("%d\n",ans );
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1010][1010] = {};
int vis[1010][1010] = {};
int p[100010] = {};
int n,m,k,x,y,ans,i,j;
void visit(int x, int y){
    if (x == 0 ||y==0||x==n+1||y == m+1) return;
    if (c[x][y] == '*') {ans++; return;}
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x+1,y);
    visit(x,y+1);
    visit(x-1,y);
    visit(x,y-1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            cin >> c[i][j];
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[100001] = {};
int n, m, k, x, y, ans, i, j;
void visit(int x, int y){
    if (x == 0 || y == 0 || x == n + 1 || y == m + 1) return;
    if (c[x][y] == '*') { ans++; return; }
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x + 1, y);
    visit(x, y + 1);
    visit(x - 1, y);
    visit(x, y - 1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            do scanf("%c",&c[i][j]); while (getchar() != '\n');
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        printf("%d\n",ans );
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[100001] = {};
int n, m, k, x, y, ans, i, j;
void visit(int x, int y){
    if (x == 0 || y == 0 || x == n + 1 || y == m + 1) return;
    if (c[x][y] == '*') { ans++; return; }
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x + 1, y);
    visit(x, y + 1);
    visit(x - 1, y);
    visit(x, y - 1);
    return;
}

char ch;
int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <= m;){
            //cin >> ch;
            ch = getchar();
            if (ch != '\n'){
                c[i][j] = ch;
                j++;
            }
        }
    }
    for (i = 1; i <= k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x, y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[100001] = {};
int n,m,k,x,y,ans,i,j;
void visit(int x, int y){
    if (x == 0 ||y==0||x==n+1||y == m+1) return;
    if (c[x][y] == '*') {ans++; return;}
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x+1,y);
    visit(x,y+1);
    visit(x-1,y);
    visit(x,y-1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            cin >> c[i][j];
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char c[1001][1001] = {};
int vis[1001][1001] = {};
int p[10001] = {};
int n,m,k,x,y,ans,i,j;
void visit(int x, int y){
    if (x == 0 ||y==0||x==n+1||y == m+1) return;
    if (c[x][y] == '*') {ans++; return;}
    if (vis[x][y] != 0) return;
    vis[x][y] = i;
    visit(x+1,y);
    visit(x,y+1);
    visit(x-1,y);
    visit(x,y-1);
    return;
}

int main(){
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++){
        for (j = 1; j <=m; j++){
            cin >> c[i][j];
        }
    }
    for (i = 1; i<=k; i++){
        cin >> x >> y;
        ans = 0;
        if (!vis[x][y]) visit(x,y);
        else ans = p[vis[x][y]];
        p[i] = ans;
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

char matrix[1000][1000] = {0};
int pic = 0;
int in = 0;
int ans[1000000] = {0};

void dfs(int x, int y){
    matrix[x][y] = in;
    if (matrix[x-1][y] == '*'){
        pic++;
    }
    if (matrix[x+1][y] == '*'){
        pic++;
    }
    if (matrix[x][y-1] == '*'){
        pic++;
    }
    if (matrix[x][y+1] == '*'){
        pic++;
    }
    if (matrix[x-1][y] == '.'){
        dfs(x-1,y);
    }
    if (matrix[x+1][y] == '.'){
        dfs(x+1,y);
    }
    if (matrix[x][y-1] == '.'){
        dfs(x,y-1);
    }
    if (matrix[x][y+1] == '.'){
        dfs(x,y+1);
    }
}

int main(){
    int x, y, s;
    cin >> x >> y >> s;
    for (int i=0; i<x; i++){
        cin >> matrix[i];
    }
    for (int i=0; i<s; i++){
        pic = 0;
        int s_x, s_y;
        cin >> s_x >> s_y;

        if (matrix[s_x - 1][s_y - 1] != '*' && matrix[s_x - 1][s_y - 1] != '.'){
            cout << ans[matrix[s_x - 1][s_y - 1]] << endl;
        }else{
            dfs(s_x - 1, s_y - 1);
            cout << pic << endl;
            ans[in] = pic;
            in++;
        }
    }
    return 0;
}


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

char matrix[1000][1000] = {0};
int pic = 0;
int in = 0;
map<int,int> ans;

void dfs(int x, int y){
    matrix[x][y] = in;
    if (matrix[x-1][y] == '*'){
        pic++;
    }
    if (matrix[x+1][y] == '*'){
        pic++;
    }
    if (matrix[x][y-1] == '*'){
        pic++;
    }
    if (matrix[x][y+1] == '*'){
        pic++;
    }
    if (matrix[x-1][y] == '.'){
        dfs(x-1,y);
    }
    if (matrix[x+1][y] == '.'){
        dfs(x+1,y);
    }
    if (matrix[x][y-1] == '.'){
        dfs(x,y-1);
    }
    if (matrix[x][y+1] == '.'){
        dfs(x,y+1);
    }
}

int main(){
    int x, y, s;
    cin >> x >> y >> s;
    for (int i=0; i<x; i++){
        cin >> matrix[i];
    }
    for (int i=0; i<s; i++){
        pic = 0;
        int s_x, s_y;
        cin >> s_x >> s_y;

        if (matrix[s_x - 1][s_y - 1] != '*' && matrix[s_x - 1][s_y - 1] != '.'){
            cout << ans[matrix[s_x - 1][s_y - 1]] << endl;
        }else{
            dfs(s_x - 1, s_y - 1);
            cout << pic << endl;
            ans[in] = pic;
            in++;
        }
    }
    return 0;
}


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

char matrix[1000][1000] = {0};
int pic = 0;
int in = 0;
unordered_map<int,int> ans;

void dfs(int x, int y){
    matrix[x][y] = in;
    if (matrix[x-1][y] == '*'){
        pic++;
    }
    if (matrix[x+1][y] == '*'){
        pic++;
    }
    if (matrix[x][y-1] == '*'){
        pic++;
    }
    if (matrix[x][y+1] == '*'){
        pic++;
    }
    if (matrix[x-1][y] == '.'){
        dfs(x-1,y);
    }
    if (matrix[x+1][y] == '.'){
        dfs(x+1,y);
    }
    if (matrix[x][y-1] == '.'){
        dfs(x,y-1);
    }
    if (matrix[x][y+1] == '.'){
        dfs(x,y+1);
    }
}

int main(){
    int x, y, s;
    cin >> x >> y >> s;
    for (int i=0; i<x; i++){
        cin >> matrix[i];
    }
    for (int i=0; i<s; i++){
        pic = 0;
        int s_x, s_y;
        cin >> s_x >> s_y;

        if (matrix[s_x - 1][s_y - 1] != '*' && matrix[s_x - 1][s_y - 1] != '.'){
            cout << ans[matrix[s_x - 1][s_y - 1]] << endl;
        }else{
            dfs(s_x - 1, s_y - 1);
            cout << pic << endl;
            ans[in] = pic;
            in++;
        }
    }
    return 0;
}


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

int n,m,k;
char mat[1005][1005];
int x,y;
bool vis[1005][1005];
bool seen[1005][1005][4];
int aux[1005][1005];
vector<int> ux,uy;
int sol;

void dfs(int x,int y)
{
    vis[x][y]=true;
    ux.push_back(x);
    uy.push_back(y);
    if(mat[x+1][y]=='.' && !vis[x+1][y]) dfs(x+1,y);
    else if(mat[x+1][y]=='*' && !seen[x+1][y][0]) sol++,seen[x+1][y][0]=true;
    if(mat[x][y+1]=='.' && !vis[x][y+1]) dfs(x,y+1);
    else if(mat[x][y+1]=='*' && !seen[x][y+1][1]) sol++,seen[x][y+1][1]=true;
    if(mat[x-1][y]=='.' && !vis[x-1][y]) dfs(x-1,y);
    else if(mat[x-1][y]=='*' && !seen[x-1][y][2]) sol++,seen[x-1][y][2]=true;
    if(mat[x][y-1]=='.' && !vis[x][y-1]) dfs(x,y-1);
    else if(mat[x][y-1]=='*' && !seen[x][y-1][3]) sol++,seen[x][y-1][3]=true;
}

void room()
{
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            if(vis[ux[i]][uy[j]])
                aux[ux[i]][uy[j]]=sol;
}

void reset()
{
    sol=0;
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            vis[ux[i]][uy[j]]=false;
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            for(int k=0; k<4; k++)
                seen[ux[i]][uy[j]][k]=false;
    ux.clear();
    uy.clear();
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0; i<n; i++) scanf("%s",mat[i]);
    while(k--)
    {
        scanf("%d%d",&x,&y);
        if(aux[x-1][y-1])
        {
            sol=aux[x-1][y-1];
            printf("%d\n",sol);
            sol=0;
        }
        else
        {
            dfs(x-1,y-1);
            room();
            printf("%d\n",sol);
            reset();
        }
    }
    return 0;
}


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

int n,m,k;
char mat[1005][1005];
int x,y;
bool vis[1005][1005];
bool seen[1005][1005][4];
int pre[1005][1005];
vector<int> ux,uy;
int sol;

void dfs(int x,int y)
{
    vis[x][y]=true;
    ux.push_back(x);
    uy.push_back(y);
    if(mat[x+1][y]=='.' && !vis[x+1][y]) dfs(x+1,y);
    else if(mat[x+1][y]=='*' && !seen[x+1][y][0]) sol++,seen[x+1][y][0]=true;
    if(mat[x][y+1]=='.' && !vis[x][y+1]) dfs(x,y+1);
    else if(mat[x][y+1]=='*' && !seen[x][y+1][1]) sol++,seen[x][y+1][1]=true;
    if(mat[x-1][y]=='.' && !vis[x-1][y]) dfs(x-1,y);
    else if(mat[x-1][y]=='*' && !seen[x-1][y][2]) sol++,seen[x-1][y][2]=true;
    if(mat[x][y-1]=='.' && !vis[x][y-1]) dfs(x,y-1);
    else if(mat[x][y-1]=='*' && !seen[x][y-1][3]) sol++,seen[x][y-1][3]=true;
}

void room()
{
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            pre[ux[i]][uy[j]]=sol;
}

void reset()
{
    sol=0;
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            vis[ux[i]][uy[j]]=false;
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            for(int k=0; k<4; k++)
                seen[ux[i]][uy[j]][k]=false;
    ux.clear();
    uy.clear();
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0; i<n; i++) scanf("%s",mat[i]);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            if(mat[i][j]=='.' && !pre[i][j])
            {
                dfs(i,j);
                room();
                reset();
            }
        }
    }
    while(k--)
    {
        scanf("%d%d",&x,&y);
        printf("%d\n",pre[x-1][y-1]);
    }
    return 0;
}


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

int n,m,k;
char mat[1005][1005];
int x,y;
bool vis[1005][1005];
bool seen[1005][1005][4];
int aux[1005][1005];
int sol;
vector<int> ux,uy;

void dfs(int x,int y)
{
    vis[x][y]=true;
    ux.push_back(x);
    uy.push_back(y);
    if(mat[x+1][y]=='.' && !vis[x+1][y]) dfs(x+1,y);
    else if(mat[x+1][y]=='*' && !seen[x+1][y][0]) sol++,seen[x+1][y][0]=true;
    if(mat[x][y+1]=='.' && !vis[x][y+1]) dfs(x,y+1);
    else if(mat[x][y+1]=='*' && !seen[x][y+1][1]) sol++,seen[x][y+1][1]=true;
    if(mat[x-1][y]=='.' && !vis[x-1][y]) dfs(x-1,y);
    else if(mat[x-1][y]=='*' && !seen[x-1][y][2]) sol++,seen[x-1][y][2]=true;
    if(mat[x][y-1]=='.' && !vis[x][y-1]) dfs(x,y-1);
    else if(mat[x][y-1]=='*' && !seen[x][y-1][3]) sol++,seen[x][y-1][3]=true;
}

void room()
{
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            if(vis[ux[i]][uy[j]])
                aux[ux[i]][uy[j]]=sol;
}

void reset()
{
    sol=0;
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            vis[ux[i]][uy[j]]=false;
    for(int i=0; i<ux.size(); i++)
        for(int j=0; j<uy.size(); j++)
            for(int k=0; k<4; k++)
                seen[ux[i]][uy[j]][k]=false;
    ux.clear();
    uy.clear();
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0; i<n; i++) scanf("%s",mat[i]);
    while(k--)
    {
        scanf("%d%d",&x,&y);
        if(aux[x-1][y-1])
        {
            sol=aux[x-1][y-1];
            printf("%d\n",sol);
            sol=0;
        }
        else
        {
            dfs(x-1,y-1);
            room();
            printf("%d\n",sol);
            reset();
        }
    }
    return 0;
}