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

#define sp(y) fixed<<setprecision(y)
#define w(t) int t;cin>>t;while(t--)
#define pi 2*acos(0.0)
#define bg begin()
#define en end()
#define all(x) x.begin(),x.end()
#define sortarr(x) sort(x,x+arrsize(x))
#define arrsize(x) sizeof(x)/sizeof(x[0])
#define sortall(x) sort(all(x))
#define formn(m,n) for(m;m<=n;m++)
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define sq(a) (a)*(a)
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
//solution
#define mx 1000005
#define m7 1000000007
int prime[mx];

void seive(){
    prime[0]=1;
    prime[1]=1;
    for(ll i=2;i<mx;i++){
        if(prime[i]==0){
            for(ll j=i*i;j<mx;j+=i){
                prime[j]=1;
            }
        }

    }
}




int solve(){
   string str;
   cin>>str;
   int len= str.size();
   reverse(all(str));

   REP(i,0,len-1){
       if(str[i]=='6'){
          str[i]='9';
       }else if(str[i]=='9'){
          str[i]='6';
       }

   }
   cout<<str;





return 0;
}
//end solution
int main(){
solve();
}

#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    vector<int> t(n);
    int m = 0;
    rep(i, n){
        cin >> t[i];
        m += t[i];
    }

    vector< vector<int> > dp(n + 1, vector<int>(m + 1, 0));
    dp[0][0] = 1;

    rep(i, n){
        rep(j, m + 1){
            dp[i + 1][j] |= dp[i][j];
            if(j + t[i] <= m){
                dp[i + 1][j + t[i]] |= dp[i][j];
            }
        }
    }

    int ans = IINF;
    rep(j, m + 1){
        if(dp[n][j]){
            chmin(ans, max(j, m - j));
        }
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}