
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<(n);i++)
#define rep2(i,n,m) for(ll i=n;i<(m);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
void YES(int a){
  if(a) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}
void Yes(int a){
  if(a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

//#include <atcoder/all>

//using namespace atcoder;
//typedef modint998244353 mint;

ll inf=1001001001001001001;

ll gcd(ll a,ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}

int main(){
  string S;
  cin>>S;
  string T;
  rep(i,S.size()){
    if(S[i]=='6') T+='9';
    else if(S[i]=='9') T+='6';
    else T+=S[i];
  }
  reverse(all(T));
  cout<<T<<endl;
}



#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007ll
#define md 998244353ll
#define e1 1e-9
#define v vector< long long >
#define vv vector< vector< long long > >
#define p pair < long long,long long >
#define vp vector< pair < long long,long long > >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ft first
#define sd second
#define all(x) x.begin() , x.end()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define bb(i,a,b) for(ll i=a;i>=0;i--)
#define test \
    ll tt{0}; \
    cin>>tt; \
    while(tt--)
using namespace std;
bool prime(ll n) {
    if (n < 2)return false;
    for (ll x = 2; x * x <= n; x++) {
        if (n % x == 0)return false;
    }
    return true;
}
vector<ll> Seiveprime(ll n)
{
    vector<bool> isPrime(n, true);
    for (int i = 2; i * i < n; i++)
    {
        if (isPrime[i])
        {
            for (int j = i * i; j < n; j += i)
                isPrime[j] = false;
        }
    }
    vector<ll> prime;
    prime.push_back(2);
    for (int i = 3; i < n; i += 2)
        if (isPrime[i])
            prime.push_back(i);
    return prime;
}
vector<ll> factors(ll n) {
    vector<ll> f;
    for (ll x = 2; x*x <= n; x++) {
        while (n%x == 0) {
            f.pb(x);
            n /= x;
        }
    }
    if (n > 1) f.pb(n);
    return f;
}
vp pri_fact(ll n) {
    v x = factors(n);
    vp y;
    y.eb(x[0], 1);

    for (ull i = 1; i < x.size(); i++) {
        if (x[i] == x[i - 1]) {
            y.back().second++;
        } else {
            y.eb(x[i], 1);
        }
    }

    return y;
}
tuple<int,int,int> gcd(int a, int b) {
    if (b == 0) {
        return {1,0,a};
    } else {
        int x,y,g;
        tie(x,y,g) = gcd(b,a%b);
        return {y,x-(a/b)*y,g};
    }
}
ll mult(ll x,ll y,ll m) {
    return (x * y) % m;
}
//returns x^n (mod m)
ll bin_pow(ll x,ll n,ll m) {
    if (n == 0)return 1;
    if (n & 1)return mult(x, bin_pow(x, n - 1, m), m);
    return bin_pow(mult(x, x, m), n / 2, m);
}
ll ind_of_2(ll x) {
    ll i = 0;

    while (x / (1 << i) != 1)
        i++;
    return i;
}
ll add(ll x,ll y)
{
    x+=y;
    if(x>=md)return x-md;
    return x;
}
ll digitno(ll n){
    ll x{0};
    while(n>0){
        x++;
        n/=10;
    }
    return x;
}

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

    bitset<100005ll> bit,bit1;
    bit[0]=1;

    ll n{0},sum{0};
    cin>>n;

    v t(n);
    f(i,0,n){
        cin>>t[i];
        sum+=t[i];
        bit= bit | (bit<<t[i]);
    }

    ll mn=INT_MAX;
    ll ans{0};
    f(i,1,100005){
        if(bit[i]){
            if(abs(sum-2*i)<mn)
            {
                mn=abs(sum-2*i);
                ans=i;
            }
        }
    }
    ans=max(ans,sum-ans);

    cout<<ans;

    return 0;
}