#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
#include <cmath>

long long CalcPoints(std::string str)
{
    int strlen = str.size();
    int pointArray[10] = {0};
    long long ret = 0;
    for(int i = 0; i < strlen; i++){
        if(str[i] == '#') continue;
        int tmp = str[i] - '0';
        pointArray[tmp]++;
    }

    for(int i = 0; i < 10; i++){
        ret += i * std::pow(10, pointArray[i]);
    }

    return ret;
}
void SetCardArray(std::vector<long long>& carray, std::string str)
{
    int strlen = str.size();

    for(int i = 0; i < strlen; i++){
        if(str[i] == '#') continue;
        carray[str[i] - '0']--;
    }
}

int main()
{
    long long a, b, c;
    std::cin >> a >> b >> c;



    std::cout << 21 - (a + b + c) << std::endl;
    return 0;
}
	
 #include <bits/stdc++.h>
 
 #define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
 #define all(v) (v).begin(), (v).end()
 using namespace  std;
 #define forn(i,n) for (int i = 0; i < (n); ++i)
 using ll = long long;
 int mod = (ll)1e9 + 7;
 #define PI acos(-1)
 typedef pair<int, int> pairs;
 
 const int INF = 1e9 + 1;
 const int N = 2e5 + 100;
 const double eps = 1e-3;
 
 template <typename XPAX>
 void ckma(XPAX &x, XPAX y) {
     x = (x < y ? y : x);
 }
 template <typename XPAX>
 void ckmi(XPAX &x, XPAX y) {
     x = (x > y ? y : x);
 }
 
 void solve() {
 
 
 	int h, w;
 	cin >> h >> w;
 	vector<vector<int>> a(h, vector<int>(w - 1));
 	forn(i, h) forn(j, w - 1) cin >> a[i][j];

 	vector<vector<int>> b(h - 1, vector<int>(w));
 	forn(i, h - 1) forn(j, w) cin >> b[i][j];
 
 	using P = tuple<int, int, int>;

 	auto myid = [&](P p) {
 		int r, c , f;
 		tie(r, c, f) = p;
 		return f * (h * w) + r * w + c;
 	};
 	using Q = pair<int, P>;

 	vector<int> dist(2 * h * w + 1, INF);
 	priority_queue<Q, vector<Q>, greater<Q>>q;
 	auto push = [&](P p, int D){
 		if(dist[myid(p)] <= D)return;
 		dist[myid(p)] = D;
 		q.push({D, p});
 	};
 	push(P{0, 0, 0}, 0);
 	auto get = [&](P p, int &r, int &c, int &f ) {
 		tie(r, c, f) = p;
 	};

 	
 	while(q.size()) {
 		Q s = q.top();
 		q.pop();
 		int D = s.first;
 		int r, c, f;
 		get(s.second, r, c, f);
 		if(r == h - 1 && c == w - 1) {
 			cout << D << endl;
 			return;
 		}
 		if(f == 0) {
 			push(P{r, c, 1}, D + 1);
 			if(c)
 				push(P{r, c - 1, f},D + a[r][c - 1]);
 			if(c + 1 < w) {
				push(P{r, c + 1, f},D + a[r][c]);
			}
			if(r + 1 < h)
				push(P{r + 1, c, f}, D + b[r][c]);

		}
		else {
			if(r) push(P{r - 1, c, f}, D + 1);

			push(P{r, c, 0}, D);
		}
	}

	

 
 }
 void test_case() {
     int t;
     cin >> t;
     forn(p, t) {
 
         //cout << "Case #" << p + 1 << ": ";
         solve();
     }
 }
 int main() {
 
     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     cout.tie(nullptr);
 
     solve();
 
 }
  
