#include <bits/stdc++.h>

#include <iostream>
#include <set>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int max(ll a, ll b) {
  if (a > b) return a;
  return b;
}
int min(ll a, ll b) {
  if (a < b) return a;
  return b;
}

int main() {
  ll a,b,c;
  cin >> a >>b >>c;  
  cout << (7-a)+(7-b)+(7-c) << endl;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int A,B,C;cin>>A>>B>>C;int s[4];
  A%=10;
  B%=4;
  s[1]=A;s[2]=(A*A)%10;s[3]=s[2]*A%10;s[0]=s[3]*A%10;
  if(B==0||B==1)cout<<s[B];
  else if(B==2){
    if(C==1)cout<<s[2];
    else cout<<s[0];
  }
  else{
    if(C%2==0)cout<<s[1];
    else cout<<s[3];
  }cout<<endl;
}