#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define _roverload(_a1, _a2, _a3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _roverload(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i)
#define rrep(...) _roverload(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << '\n'; }
template <class T>
void print(const vector<T> &v) {
    bool f = false;
    for (const auto &e : v) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
template <class... T>
void print(const T &...args) {
    bool f = false;
    for (const auto &e : {args...}) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vi ls1 = {a % 10};
    ll now = a % 10;
    while (true) {
        now *= a;
        now %= 10;
        if (ls1[0] != now) {
            ls1.emplace_back(now);
        } else {
            break;
        }
    }
    int len = ls1.size();
    vi ls2 = {b % len};
    ll now2 = b % len;
    bool flag = false;
    int cnt = 1;
    while (true) {
        cnt++;
        now2 *= b;
        now2 %= len;
        if (now2 == 0) {
            flag = true;
            break;
        } else if (ls2[0] != now2) {
            ls2.emplace_back(now2);
        } else {
            break;
        }
    }
    int s2 = ls2[(c - 1 + ls2.size()) % ls2.size()];
    if (flag && cnt<=c) s2 = 0;
    int s1 = ls1[(s2 - 1 + ls1.size()) % ls1.size()];
    print(s1);
}
#include<bits/stdc++.h>
using namespace std;
int main () { int N ;cin>>N;
               string s ;int y;cin>>y>>s; int i;
                              
                              for(i=0;i< s.length();i++){
                                   if(y!=0){if(s[i]=='o') {y=y+1;}
                                    else if (s[i]=='x'){y=y-1;}}
                                else if(y==0){if(s[i]=='o') {y=y+1;}
                                              else if (s[i]=='x'){y=y;}}}
                            
                               cout<<y;
                                return 0; }