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

int n, cnt, cl[128];
vector <int> g[128];

void dfs(int v, int p) {
  cl[v] = 1;
  for (int u : g[v]) {
    if (u == p) continue;
    if (!cl[u]) dfs(u, v);
    else if (cl[u] == 1) {
      cl[u] = 2;
      cnt++;
    }
  }
  cl[v] = 2;
}

int main() {
  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  if (cnt == 1) cout << "FHTAGN!";
  else cout << "NO";
}


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

int n, cnt, cl[128];
vector <int> g[128];

void dfs(int v, int p) {
  cl[v] = 1;
  for (int u : g[v]) {
    if (u == p) continue;
    if (!cl[u]) dfs(u, v);
    else if (cl[u] == 1) {
      cnt++;
    }
  }
  cl[v] = 2;
}

int main() {
  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    dfs(i, 0);
  }
  if (cnt == 1 && n > 3) cout << "FHTAGN!";
  else cout << "NO";
}


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

int n, cnt, cl[128];
vector <int> g[128];

void dfs(int v, int p) {
  cl[v] = 1;
  for (int u : g[v]) {
    if (u == p) continue;
    if (!cl[u]) dfs(u, v);
    else if (cl[u] == 1) {
      cl[u] = 2;
      cnt++;
    }
  }
  cl[v] = 2;
}

int main() {
  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    dfs(i, 0);
  }
  if (cnt == 1) cout << "FHTAGN!";
  else cout << "NO";
}


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

int n, cnt, cl[128];
vector <int> g[128];

void dfs(int v, int p) {
  cl[v] = 1;
  for (int u : g[v]) {
    if (u == p) continue;
    if (!cl[u]) dfs(u, v);
    else if (cl[u] == 1) {
      cnt++;
    }
  }
  cl[v] = 2;
}

int main() {
  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    dfs(i, 0);
  }
  if (cnt == 1) cout << "FHTAGN!";
  else cout << "NO";
}


#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

int cycle;
struct dsu
{
    vector<int> par;
    void init(int n)
    {
        par.resize(n);
        for (int i = 0; i < n; i++)
            par[i] = i;
    }
    int get(int x)
    {
        return (x == par[x]) ? x : par[x] = get(par[x]);
    }

    bool unite(int x, int y)
    {
        x = get(x);
        y = get(y);
        if (x == y)
            cycle++;
        else
        par[y] = x;
        return true;
    }
}G;
int32_t main()
{
    int n, m;
    cin >> n >> m;
    G.init(n);
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G.unite(x, y);
    }

    set<int> comp;
    for (int i = 0; i < n; i++)
        comp.insert(G.get(i));

    //only one cycle and only one super parent
    if (cycle == 1 && comp.size() == 1)
        cout <<"FHTAGN!";
    else
        cout <<"NO\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ins insert
typedef pair<int, int> pii;

vector<int> g[110];
int vis[110];
int pai;

void dfs(int v) {
    vis[v] = 1;
    for(int i : g[v]){
        if(vis[i] == -1){
            dfs(i);
        }
    }
}

int main() {

    int n, m, x, y; // qtd vertice, qtd arestas
    bool flag = true, conexo = true;
    string out;
    memset(vis, -1, sizeof vis);
    cin >> n >> m;

    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    for(int i = 1; i <= n; ++i) {

        if(vis[i] == -1) {
            dfs(i);

            if(!flag || m != n) {
                conexo = false;
                break;
            }
            flag = false;
        } else continue;
    }

    out = conexo ? "FHTAGN!" : "NO";
    cout << out << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ins insert
typedef pair<int, int> pii;

vector<int> g[110];
int vis[110];
int pai;

void dfs(int v) {
    vis[v] = 1;
    for(int i : g[v]){
        if(vis[i] == -1){
            dfs(i);
        }
    }
}

int main() {

    int n, m, x, y; // qtd vertice, qtd arestas
    bool flag = true, conexo = true;
    string out;
    memset(vis, -1, sizeof vis);
    cin >> n >> m;

    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    for(int i = 1; i <= n; ++i) {

        if(vis[i] == -1) {
            pai = i;
            dfs(i);

            if(!flag || m < n) {
                conexo = false;
                break;
            }
            flag = false;
        } else continue;
    }

    out = conexo ? "FHTAGN!" : "NO";
    cout << out << endl;

    return 0;
}


/*input
3 3
1 2
2 3
3 1
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];

vi stk;
bool cycle(int u ){
    dfs_num[u] = EXPLORED;
    lp(i,graph[u].size(),1){
        int edge = graph[u][i];
        if(dfs_num[edge] == UNVISITED){
        // printf("from %d u get : %d\n",u, edge);
            parent[edge]=u;
            cycle(edge);
        }else if(dfs_num[edge] == EXPLORED){
            if(edge != parent[u] ){
                // printf("%d %d\n", parent[u]+1 , edge+1);
                // printf("-- Back edge between %d - %d.\n", edge,u);
                // stk.pb(edge);
                return true;
            }
        }
    }
    dfs_num[u]=VISITED;
    return false;
}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(dfs_num,dfs_num+n+1,UNVISITED);
  fill(parent,parent+n+10,0);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }

    if(n == m){
        if(cycle(0)){
            printf("FHTAGN!\n");
        }else{
            printf("NO!\n");
        }
    }else{
        printf("NO\n");
    }
 return 0;

}


/*input
3 3
1 2
2 3
3 1
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];

vi stk;
bool cycle(int u ){
    dfs_num[u] = EXPLORED;
    lp(i,graph[u].size(),1){
        int edge = graph[u][i];
        if(dfs_num[edge] == UNVISITED){
        // printf("from %d u get : %d\n",u, edge);
            parent[edge]=u;
            cycle(edge);
        }else if(dfs_num[edge] == EXPLORED){
            if(edge != parent[u] ){
                // printf("%d %d\n", parent[u]+1 , edge+1);
                // printf("-- Back edge between %d - %d.\n", edge,u);
                // stk.pb(edge);
                return true;
            }
        }
    }
    dfs_num[u]=VISITED;
    return false;
}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(dfs_num,dfs_num+n+1,UNVISITED);
  fill(parent,parent+n+10,0);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }

    if(n == m){
        printf("FHTAGN!\n");
    }else{
        printf("NO\n");
    }
 return 0;

}


/*input
6 6
6 3
6 4
5 1
2 5
1 4
5 4
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];

const int MAX = 3005;
bool visited[MAX], flag=false;
vi graph[MAX];
int parent[MAX], dist[MAX], z;

void dfs(int from)
{
    visited[from] = true;
    lp(i,(int)graph[from].size(), 1)
    {
        int to = graph[from][i];
        if(visited[to] == false)
        {
            parent[to] = from;
            dfs(to);
        }
        else if(parent[from] != to and flag)
        {
            z = to;
            parent[to] = from;
            flag = false;
            // cout << from << ' ' << to << endl;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  flag = true;
  fill(parent,parent+n+1,0);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }
  dfs(0);
  z=0;
  if(flag){
    printf("NO\n");
  }else{
    printf("FHTAGN!\n");
  }
 return 0;

}


/*input
6 5
5 6
4 6
3 1
5 1
1 2
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];

vi stk;
bool cycle(int u ){
    dfs_num[u] = EXPLORED;
    stk.pb(u);
    lp(i,graph[u].size(),1){
        int edge = graph[u][i];
        if(dfs_num[edge] == UNVISITED){
        // printf("from %d u get : %d\n",u, edge);
            parent[edge]=u;
            stk.pb(edge);
            cycle(edge);
        }else if(dfs_num[edge] == EXPLORED){
            if(edge != parent[u] ){
                // printf("%d %d\n", parent[u]+1 , edge+1);
                // printf("-- Back edge between %d - %d.\n", edge,u);
                // stk.pb(edge);
                return true;
            }
        }
    }
    dfs_num[u]=VISITED;

}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(dfs_num,dfs_num+n+1,UNVISITED);
  fill(parent,parent+n+1,0);
  fill(dfs_low,dfs_low+n+1,UNVISITED);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }
    LL ans=0;
    lp(i,n,1){
        if(dfs_num[i] == UNVISITED){
            ans +=  cycle(i);
        }
    }
    if(ans == 1){
        printf("FHTAGN!\n");
    }else{
        printf("N0\n");
    }
 return 0;

}


/*input
3 3
1 2
2 3
3 1
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];

vi stk;
bool cycle(int u ){
    dfs_num[u] = EXPLORED;
    stk.pb(u);
    lp(i,graph[u].size(),1){
        int edge = graph[u][i];
        if(dfs_num[edge] == UNVISITED){
        // printf("from %d u get : %d\n",u, edge);
            parent[edge]=u;
            stk.pb(edge);
            cycle(edge);
        }else if(dfs_num[edge] == EXPLORED){
            if(edge != parent[u] ){
                // printf("%d %d\n", parent[u]+1 , edge+1);
                // printf("-- Back edge between %d - %d.\n", edge,u);
                // stk.pb(edge);
                return true;
            }
        }
    }
    dfs_num[u]=VISITED;
    return false;
}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(dfs_low,dfs_low+n+1,UNVISITED);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }
    LL ans=0;
    lp(i,n,1){
        fill(dfs_num,dfs_num+n+1,UNVISITED);
        fill(parent,parent+n+1,0);
            // printf("%d %d\n", i,cycle(i));
            ans +=  cycle(i);
    }
    // printf("%lld\n", ans);
    if(ans/3 == 1){
        printf("FHTAGN!\n");
    }else{
        printf("NO\n");
    }
 return 0;

}


/*input
6 5
5 6
4 6
3 1
5 1
1 2
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];

vi stk;
bool cycle(int u ){
    dfs_num[u] = EXPLORED;
    stk.pb(u);
    lp(i,graph[u].size(),1){
        int edge = graph[u][i];
        if(dfs_num[edge] == UNVISITED){
        // printf("from %d u get : %d\n",u, edge);
            parent[edge]=u;
            stk.pb(edge);
            cycle(edge);
        }else if(dfs_num[edge] == EXPLORED){
            if(edge != parent[u] ){
                // printf("%d %d\n", parent[u]+1 , edge+1);
                // printf("-- Back edge between %d - %d.\n", edge,u);
                // stk.pb(edge);
                return true;
            }
        }
    }
    dfs_num[u]=VISITED;

}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(dfs_low,dfs_low+n+1,UNVISITED);
  fill(dfs_num,dfs_num+n+1,UNVISITED);
  fill(parent,parent+n+1,0);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }
    LL ans=0;
    lp(i,n,1){
        if(dfs_num[i] == UNVISITED){
            ans +=  cycle(i);
        }
    }
    if(ans == 1){
        printf("FHTAGN!\n");
    }else{
        printf("NO\n");
    }
 return 0;

}


/*input
6 6
6 3
6 4
5 1
2 5
1 4
5 4
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];

vi stk;
bool cycle(int u ){
    dfs_num[u] = EXPLORED;
    stk.pb(u);
    lp(i,graph[u].size(),1){
        int edge = graph[u][i];
        if(dfs_num[edge] == UNVISITED){
        // printf("from %d u get : %d\n",u, edge);
            parent[edge]=u;
            stk.pb(edge);
            cycle(edge);
        }else if(dfs_num[edge] == EXPLORED){
            if(edge != parent[u] ){
                // printf("%d %d\n", parent[u]+1 , edge+1);
                // printf("-- Back edge between %d - %d.\n", edge,u);
                // stk.pb(edge);
                return true;
            }
        }
    }
    dfs_num[u]=VISITED;

}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(dfs_low,dfs_low+n+1,UNVISITED);
  fill(dfs_num,dfs_num+n+1,UNVISITED);
  fill(parent,parent+n+1,0);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }
    LL ans=0;
    lp(i,n,1){
        if(dfs_num[i] == UNVISITED){
            ans +=  cycle(i);
        }
    }
    if(ans == 1){
        printf("FHTAGN!\n");
    }else{
        printf("N0\n");
    }
 return 0;

}


/*input
3 3
1 2
2 3
3 1
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int vis[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];
bool f=false;
vi stk;
void cycle(int u ){
    vis[u]=1;
    lp(i,graph[u].size(),1){
        int v = graph[u][i];
        if(!vis[v])
            cycle(v);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(vis,vis+n+1,0);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }

    if(n == m){
        cycle(0);
        lp(i,n,1){
            if(!vis[i]){
                printf("NO\n");
                return 0;
            }
        }
        printf("FHTAGN!\n");
    }else{
        printf("NO\n");
    }
 return 0;

}


/*input
10 10
4 10
8 5
2 8
4 9
9 3
2 7
10 6
10 2
9 8
1 8
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <string> vs;
typedef map <string,int> msi;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define lp(i,j,k) for(int i=0;i<j;i+=k)
#define lpe(i,j,k) for(int a=i;a<=j;i+=k)
#define bitcount(x) __builtin_popcount(x)
int power(int x, unsigned int y){
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

#define VISITED 1
#define UNVISITED -1
#define EXPLORED 0

int dfs_num[1000];
int dfs_low[1000];
int parent[1000];

vi graph[1000];
bool f=false;
vi stk;
bool cycle(int u ){
    dfs_num[u] = EXPLORED;
    lp(i,graph[u].size(),1){
        int edge = graph[u][i];
        if(dfs_num[edge] == UNVISITED){
        // printf("from %d u get : %d\n",u, edge);
            parent[edge]=u;
            cycle(edge);
        }else if(dfs_num[edge] == EXPLORED){
            if(edge != parent[u] ){
                // printf("%d %d\n", parent[u]+1 , edge+1);
                // printf("-- Back edge between %d - %d.\n", edge,u);
                // stk.pb(edge);
                f =true;
                return true;
            }
        }
    }
    dfs_num[u]=VISITED;
    return false;
}

int main(){
    ios_base::sync_with_stdio(0);
  // freopen("in.txt", "r", stdin);
  // freopen("out.out", "w", stdout);
  int n,m,x,y;
  cin>>n>>m;
  fill(dfs_num,dfs_num+n+1,UNVISITED);
  fill(parent,parent+n+10,0);
  lp(i,m,1){
    cin>>x>>y;
    // printf("%d %d\n", x-1,y-1);
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }

    if(n == m){
        cycle(0);
        if(f){
            printf("FHTAGN!\n");
        }else{
            printf("NO!\n");
        }
    }else{
        printf("NO\n");
    }
 return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi  vector<int>
#define pb  push_back
#define mp  make_pair
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define print(x) printf("%d",x);
#define nl printf("\n")
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000000000000LL
#define LL long long

const int N = 1e5+5;
vi adj[N];
int visited[N];

bool dfs(int u) {
    visited[u]=true;
    for(int i=0;i<adj[u].size();i++) {
	int v=adj[u][i];
	if(!visited[v]) {
	    dfs(v);
	}
    }
}
int main() {
    int n,m;sci(n);sci(m);
    for(int i=0;i<m;i++) {
	int x,y;sci(x);sci(y);
	adj[x].pb(y);
	adj[y].pb(x);
    }
//    cout<<n<<" "<<m<<endl;
    if(n!=m) {
	puts("NO");
	return 0;
    }
    int cnt=0;
    for(int i=1;i<=n;i++) {
	if(!visited[i]) {
	    dfs(i);
	    cnt++;
	}
    }
//    cout<<cnt<<endl;
    if(cnt!=1) {
	puts("NO");
	return 0;
    }
    puts("FHTAGN!");
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi  vector<int>
#define pb  push_back
#define mp  make_pair
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define print(x) printf("%d",x);
#define nl printf("\n")
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000000000000LL
#define LL long long

const int N = 1e5+5;
struct node {
  int v;
  struct node * next;
};
int visited[N];
struct node * adj[N];
bool dfs(int u) {
  visited[u]=true;
  struct node * itr;
  for(itr = adj[u];itr!=NULL;itr = itr->next) {
    int v=itr->v;
    if(!visited[v]) {
      dfs(v);
    }
  }
}
int main() {
  int n,m;sci(n);sci(m);
  for(int i=0;i<=n;i++) {
    adj[i] = NULL;
  }
  for(int i=0;i<m;i++) {
    int x,y;sci(x);sci(y);
    struct node * temp = (struct node *)malloc(sizeof(node));
    temp->next = NULL;
    temp->v = y;
    if(adj[x] == NULL) {
      adj[x] = temp;
    }
    else {
      temp->next = adj[x]->next;
      adj[x]->next = temp;
    }
    struct node * temp2 = (struct node *)malloc(sizeof(node));
    temp2->next = NULL;
    temp2->v = x;
    if(adj[y] == NULL) {
      adj[y] = temp2;
    }
    else {
      temp2->next = adj[y]->next;
      adj[y]->next = temp2;
    }
  }
  //    cout<<n<<" "<<m<<endl;
  if(n!=m) {
    puts("NO");
    return 0;
  }
  int cnt=0;
  for(int i=1;i<=n;i++) {
    if(!visited[i]) {
      dfs(i);
      cnt++;
    }
  }
//  return 0;
  //    cout<<cnt<<endl;
  if(cnt!=1) {
    puts("NO");
    return 0;
  }
  puts("FHTAGN!");
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,m;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
	}
	cout<<(n==m?"FHTAGN!":"NO")<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,m;
int pre[105];
int fnd(int x)
{
	if(pre[x]!=x) pre[x]=fnd(pre[x]);
	return pre[x];
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		pre[i]=i;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		pre[fnd(x)]=fnd(y);
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(pre[i]==i)
			cnt++;
	cout<<(n==m&&cnt==1?"FHTAGN!":"NO")<<endl;
	return 0;
}


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

void initialize( int Arr[ ],int size1[], int N)
{
    for(int i = 0;i<N;i++)
    {
    Arr[ i ] = i ;
    size1[ i ] = 1;
   }
}

int root (int Arr[ ] ,int i) //with path compression
{
    while(Arr[ i ] != i)
    {
        Arr[ i ] = Arr[ Arr[ i ] ] ;
        i = Arr[ i ];
    }
    return i;
}

bool find(int arr[],int A,int B)
{
    if( root(arr,A)==root(arr,B) )       //if A and B have same root,means they are connected.
    return true;
    else
    return false;
}

void weighted_union(int Arr[ ],int size1[ ],int A,int B)
{
    int root_A = root(Arr,A);
    int root_B = root(Arr,B);
    if(size1[root_A] < size1[root_B ])
    {
     Arr[ root_A ] = Arr[root_B];
     size1[root_B] += size1[root_A];
    }
    else
    {
     Arr[ root_B ] = Arr[root_A];
     size1[root_A] += size1[root_B];
    }

}
int main()
{
    int n,m,cnt=0,root1;
    cin>>n>>m;
    string ans= "NO";
    int arr[n+1];
    int size1[n+1];
    initialize(arr,size1,n+1);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(find(arr,x,y)==true)
          {
              root1=root(arr,x);
              cnt++;

          }
        else
         weighted_union(arr,size1,x,y);
    }
    if (cnt==1 && size1[root1]==n)
        cout<<"FHTAGN!";
    else
      cout<<ans;
    return 0;
}


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

void initialize( int Arr[ ],int size1[], int N)
{
    for(int i = 0;i<N;i++)
    {
    Arr[ i ] = i ;
    size1[ i ] = 1;
   }
}

int root (int Arr[ ] ,int i) //with path compression
{
    while(Arr[ i ] != i)
    {
        Arr[ i ] = Arr[ Arr[ i ] ] ;
        i = Arr[ i ];
    }
    return i;
}

bool find(int arr[],int A,int B)
{
    if( root(arr,A)==root(arr,B) )       //if A and B have same root,means they are connected.
    return true;
    else
    return false;
}

void weighted_union(int Arr[ ],int size1[ ],int A,int B)
{
    int root_A = root(Arr,A);
    int root_B = root(Arr,B);
    if(size1[root_A] < size1[root_B ])
    {
     Arr[ root_A ] = Arr[root_B];
     size1[root_B] += size1[root_A];
    }
    else
    {
     Arr[ root_B ] = Arr[root_A];
     size1[root_A] += size1[root_B];
    }

}
int main()
{
    int n,m,cnt=0;;
    cin>>n>>m;
    string ans= "NO";
    int arr[n+1];
    int size1[n+1];
    initialize(arr,size1,n+1);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(find(arr,x,y)==true)
          {
              cnt++;

          }
        else
         weighted_union(arr,size1,x,y);
    }
    if (cnt==1)
        cout<<"FHTAGN!";
    else
      cout<<ans;
    return 0;
}


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

void initialize( int Arr[ ],int size1[], int N)
{
    for(int i = 0;i<N;i++)
    {
    Arr[ i ] = i ;
    size1[ i ] = 1;
   }
}

int root (int Arr[ ] ,int i) //with path compression
{
    while(Arr[ i ] != i)
    {
        Arr[ i ] = Arr[ Arr[ i ] ] ;
        i = Arr[ i ];
    }
    return i;
}

bool find(int arr[],int A,int B)
{
    if( root(arr,A)==root(arr,B) )       //if A and B have same root,means they are connected.
    return true;
    else
    return false;
}

void weighted_union(int Arr[ ],int size1[ ],int A,int B)
{
    int root_A = root(Arr,A);
    int root_B = root(Arr,B);
    if(size1[root_A] < size1[root_B ])
    {
     Arr[ root_A ] = Arr[root_B];
     size1[root_B] += size1[root_A];
    }
    else
    {
     Arr[ root_B ] = Arr[root_A];
     size1[root_A] += size1[root_B];
    }

}
int main()
{
    int n,m,cnt=0;;
    cin>>n>>m;
    string ans= "NO";
    int arr[n+1];
    int size1[n+1];
    initialize(arr,size1,n+1);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(find(arr,x,y)==true)
          {
              cnt++;
              initialize(arr,size1,n+1);
          }
        else
         weighted_union(arr,size1,x,y);
    }
    if (cnt==1)
        cout<<"FHTAGN!";
    else
      cout<<ans;
    return 0;
}


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

void initialize( int Arr[ ],int size1[], int N)
{
    for(int i = 0;i<N;i++)
    {
    Arr[ i ] = i ;
    size1[ i ] = 1;
   }
}

int root (int Arr[ ] ,int i) //with path compression
{
    while(Arr[ i ] != i)
    {
        Arr[ i ] = Arr[ Arr[ i ] ] ;
        i = Arr[ i ];
    }
    return i;
}

bool find(int arr[],int A,int B)
{
    if( root(arr,A)==root(arr,B) )       //if A and B have same root,means they are connected.
    return true;
    else
    return false;
}

void weighted_union(int Arr[ ],int size1[ ],int A,int B)
{
    int root_A = root(Arr,A);
    int root_B = root(Arr,B);
    if(size1[root_A] < size1[root_B ])
    {
     Arr[ root_A ] = Arr[root_B];
     size1[root_B] += size1[root_A];
    }
    else
    {
     Arr[ root_B ] = Arr[root_A];
     size1[root_A] += size1[root_B];
    }

}
int main()
{
    int n,m;
    cin>>n>>m;
    string ans= "NO";
    int arr[n+1];
    int size1[n+1];
    initialize(arr,size1,n+1);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(find(arr,x,y)==true)
          ans= "FHTAGN!";
        else
         weighted_union(arr,size1,x,y);
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#include<string>
//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fff				            ios_base::sync_with_stdio(0);cin.tie(0)
#define _for(i,_)		            for(int i=0 ; i<_ ; i++)
#define _forr(i,_)                  for(int i=1 ; i<=_ ; i++)
#define _rof(i,_)		            for(int i=_-1 ; i>=0 ; i--)
#define _roff(i,_)          		for(int i=_ ; i>=1 ; i--)
#define _all(_)	            		_.begin() , _.end()
#define _in(_)	            		int _; cin >> _
#define _mp(_,__)	            	make_pair(_,__)
#define _pause	            		system("pause")
#define _cls	            		system("cls")
#define NL			            	cout << endl
#define SP				            cout << " "
#define pb          				push_back
#define pp	            			pop_back
#define BIG         				INT_MAX
#define LBIG         				LONG_MAX
#define inf         				INT_MAX
#define ss		            		second
#define ff				            first
using namespace                     std;
typedef	long long                   ll;
typedef long double        			ld;
typedef	map<int,int>                mi;
typedef	pair<int,int>               pii;
typedef	pair<ll,ll>                 pl;
typedef	pair<char,int>              pci;
typedef	pair<string,int>            psi;
typedef	vector<int>				    vi;
typedef	vector<ll>				    vl;
typedef	vector<pl>				    vp;
typedef	vector<string>			    vs;
const int mod = 1000000007;
const int MAX = 300200;

ll n, m, x, y, sum, vis[MAX], f;
vl d[MAX];

void dfs(ll u, ll v = -1)
{
    vis[u] = 1;
    _for(i,d[u].size())
    {
        if(vis[d[u][i]] == 0)
            dfs(d[u][i], u);
        else if(vis[d[u][i]] == 1 && d[u][i] != v && v != -1)
            f = 1;
    }
}

int main()
{
    fff;
    cin >> n >> m;
    _for(i,m)
        cin >> x >> y,
        d[x].pb(y),
        d[y].pb(x);
    dfs(1);
    _forr(i,n)
        if(vis[i] == 0)
            f = 0;
    if(f)
        cout << "FHTAGN!";
    else
        cout << "NO";
}


#include<bits/stdc++.h>
#include<string>
//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fff				            ios_base::sync_with_stdio(0);cin.tie(0)
#define _for(i,_)		            for(int i=0 ; i<_ ; i++)
#define _forr(i,_)                  for(int i=1 ; i<=_ ; i++)
#define _rof(i,_)		            for(int i=_-1 ; i>=0 ; i--)
#define _roff(i,_)          		for(int i=_ ; i>=1 ; i--)
#define _all(_)	            		_.begin() , _.end()
#define _in(_)	            		int _; cin >> _
#define _mp(_,__)	            	make_pair(_,__)
#define _pause	            		system("pause")
#define _cls	            		system("cls")
#define NL			            	cout << endl
#define SP				            cout << " "
#define pb          				push_back
#define pp	            			pop_back
#define BIG         				INT_MAX
#define LBIG         				LONG_MAX
#define inf         				INT_MAX
#define ss		            		second
#define ff				            first
using namespace                     std;
typedef	long long                   ll;
typedef long double        			ld;
typedef	map<int,int>                mi;
typedef	pair<int,int>               pii;
typedef	pair<ll,ll>                 pl;
typedef	pair<char,int>              pci;
typedef	pair<string,int>            psi;
typedef	vector<int>				    vi;
typedef	vector<ll>				    vl;
typedef	vector<pl>				    vp;
typedef	vector<string>			    vs;
const int mod = 1000000007;
const int MAX = 300200;

ll n, m, x, y, sum, vis[MAX], f;
vl d[MAX];

void dfs(ll u, ll v = -1)
{
    vis[u] = 1;
    _for(i,d[u].size())
    {
        if(vis[d[u][i]] == 0)
            dfs(d[u][i], u);
        else if(vis[d[u][i]] == 1 && d[u][i] != v && v != -1)
            f++;
    }
}

int main()
{
    fff;
    cin >> n >> m;
    _for(i,m)
        cin >> x >> y,
        d[x].pb(y),
        d[y].pb(x);
    dfs(1);
    _forr(i,n)
        if(vis[i] == 0)
            f = 0;
    if(f == 1)
        cout << "FHTAGN!";
    else
        cout << "NO";
}


n = int(input())
dic = {}
dic2 = {}
lis = []
for i in range(n):
    name,y = input().split()
    score = int(y)
    if name in dic:
        dic[name]+=score
    else:
        dic[name]=score
    lis.append((name,score))

m = max(list(dic.values()))
for i in range(n):
    if lis[i][0] in dic2:
        dic2[lis[i][0]]+=lis[i][1]
    else:
        dic2[lis[i][0]]=lis[i][1]
    if dic2[lis[i][0]]==m:
        final = lis[i][0]
        break
print(final)


n = int(input())
dic = {}
dic2 = {}
lis = []
for i in range(n):
    name,y = input().split()
    score = int(y)
    if name in dic:
        dic[name]+=score
    else:
        dic[name]=score
    lis.append((name,score))

m = max(list(dic.values()))
for i in range(n):
    if lis[i][0] in dic2:
        dic2[lis[i][0]]+=lis[i][1]
    else:
        dic2[lis[i][0]]=lis[i][1]
    if dic2[lis[i][0]]>=m and dic[lis[i][0]]==m:
        final = lis[i][0]
        break
print(final)


n = int(input())
dic = {}
dic2 = {}
lis = []
for i in range(n):
    name,y = input().split()
    score = int(y)
    if name in dic:
        dic[name]+=score
    else:
        dic[name]=score
    lis.append((name,score))

m = max(list(dic.values()))
for i in range(n):
    if lis[i][0] in dic2:
        dic2[lis[i][0]]+=lis[i][1]
    else:
        dic2[lis[i][0]]=lis[i][1]
    if dic2[lis[i][0]]==m and dic[lis[i][0]]==m:
        final = lis[i][0]
        break
print(final)


input = input("").split("\n")

first = True
entries = {}

iteration = 0

for line in input:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score
		user_data["iteration"] = iteration
		user_data["lost"] = score < 0
	else:
		user_data = {
			"name": name,
			"score": score,
			"iteration": iteration,
			"lost": score < 0
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score
winner = None

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score == maximum and (winner == None or user_data["iteration"] < winner["iteration"]):
		winner = user_data
if winner != None:
	print(winner["name"], winner["score"])


import sys

first = True
entries = {}

iteration = 0

for line in sys.stdin:
#file = open("input.txt", "r")
#for line in file:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score

		user_score = user_data["score"]

		user_data["tracker"].append((user_score, iteration))
	else:
		user_data = {
			"name": name,
			"score": score,
			"tracker": [(score, iteration)]
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score

def get_at_least_i(user_data, maximum):
	minimum = 10000000000

	for entry in user_data["tracker"]:
		if entry[0] >= maximum and entry[1] < minimum:
			minimum = entry[1]
	return minimum

winner = None
defending_i = -1

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score != maximum:
		continue
	if winner == None:
		winner = user_data
		defending_i = get_at_least_i(user_data, maximum)
		continue
	competing_i = get_at_least_i(user_data, maximum)

	if competing_i < defending_i:
		winner = user_data
		defending_i = competing_i
print(winner["name"])


import sys

first = True
entries = {}

iteration = 0

for line in sys.stdin:
#file = open("input.txt", "r")
#for line in file:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score

		user_score = user_data["score"]

		user_data["tracker"].append((user_score, iteration))
	else:
		user_data = {
			"name": name,
			"score": score,
			"tracker": [(score, iteration)]
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score

def get_at_least_i(user_data, maximum):
	minimum = 10000000000

	for entry in user_data["tracker"]:
		if entry[0] > maximum and entry[1] < minimum:
			minimum = entry[1]
	return maximum

winner = None
defending_i = -1

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score != maximum:
		continue
	if winner == None:
		winner = user_data
		defending_i = get_at_least_i(user_data, maximum)
		continue
	competing_i = get_at_least_i(user_data, maximum)

	if competing_i < defending_i:
		winner = user_data
		defending_i = competing_i
print(winner["name"])


import sys

first = True
entries = {}

iteration = 0

#for line in sys.stdin:
file = open("input.txt", "r")
for line in file:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score

		user_score = user_data["score"]

		user_data["tracker"].append((user_score, iteration))
	else:
		user_data = {
			"name": name,
			"score": score,
			"tracker": [(score, iteration)]
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score

def get_at_least_i(user_data, maximum):
	minimum = 10000000000

	for entry in user_data["tracker"]:
		if entry[0] >= maximum and entry[1] < minimum:
			minimum = entry[1]
	return minimum

winner = None
defending_i = -1

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score != maximum:
		continue
	if winner == None:
		winner = user_data
		defending_i = get_at_least_i(user_data, maximum)
		continue
	competing_i = get_at_least_i(user_data, maximum)

	if competing_i < defending_i:
		winner = user_data
		defending_i = competing_i
print(winner["name"])


import sys

first = True
entries = {}

iteration = 0

#for line in sys.stdin:
file = open("input.txt", "r")
for line in file:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score

		user_score = user_data["score"]

		user_data["tracker"].append((user_score, iteration))
	else:
		user_data = {
			"name": name,
			"score": score,
			"tracker": [(score, iteration)]
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score

def get_at_least_i(user_data, maximum):
	minimum = 10000000000

	for entry in user_data["tracker"]:
		if entry[0] > maximum and entry[1] < minimum:
			minimum = entry[1]
	return maximum

winner = None
defending_i = -1

for name in entries:
    user_data = entries[name]
    score = user_data["score"]

    if score != maximum:
        continue
	if winner == None:
		winner = user_data
		defending_i = get_at_least_i(user_data, maximum)
		continue
	competing_i = get_at_least_i(user_data, maximum)

	if competing_i < defending_i:
		winner = user_data
		defending_i = competing_i
print(winner["name"])


import sys

first = True
entries = {}

iteration = 0

for line in sys.stdin:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score
		user_data["iteration"] = iteration
		user_data["lost"] = score < 0
	else:
		user_data = {
			"name": name,
			"score": score,
			"iteration": iteration,
			"lost": score < 0
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score
winner = None

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score == maximum and (winner == None or user_data["iteration"] < winner["iteration"]):
		winner = user_data
if winner != None:
	print(winner["name"])


input = input().split("\n")

first = True
entries = {}

iteration = 0

for line in input:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score
		user_data["iteration"] = iteration
		user_data["lost"] = score < 0
	else:
		user_data = {
			"name": name,
			"score": score,
			"iteration": iteration,
			"lost": score < 0
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score
winner = None

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score == maximum and (winner == None or user_data["iteration"] < winner["iteration"]):
		winner = user_data
if winner != None:
	print(winner["name"], winner["score"])


import sys

first = True
entries = {}

iteration = 0

for line in sys.stdin:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score
		user_data["iteration"] = iteration
		user_data["lost"] = score < 0
	else:
		user_data = {
			"name": name,
			"score": score,
			"iteration": iteration,
			"lost": score < 0
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score
winner = None

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score == maximum and (winner == None or user_data["iteration"] < winner["iteration"]):
		winner = user_data
if winner != None:
	print(winner["name"], winner["score"])


import sys

first = True
entries = {}

iteration = 0

for line in sys.stdin:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score
		user_data["iteration"] = iteration
		user_data["lost"] = score < 0
	else:
		user_data = {
			"name": name,
			"score": score,
			"iteration": iteration,
			"lost": score < 0
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score
winner = None

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score == maximum and (winner == None or user_data["iteration"] < winner["iteration"] or (winner["lost"] and not user_data["lost"])):
		winner = user_data
if winner != None:
	print(winner["name"])


import sys

first = True
entries = {}

iteration = 0

#for line in sys.stdin:
file = open("input.txt", "r")
for line in file:
	if first:
		first = False
		continue
	data = line.split(" ")
	name = data[0]
	score = int(data[1])

	if name in entries:
		user_data = entries[name]
		user_data["score"] += score

		user_score = user_data["score"]

		user_data["tracker"].append((user_score, iteration))
	else:
		user_data = {
			"name": name,
			"score": score,
			"tracker": [(score, iteration)]
		}
		entries[name] = user_data
	iteration += 1
maximum = -10000000000 #lowest you can

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score > maximum:
		maximum = score

def get_at_least_i(user_data, maximum):
	minimum = 10000000000

	for entry in user_data["tracker"]:
		if entry[0] > maximum and entry[1] < minimum:
			minimum = entry[1]
	return maximum

winner = None
defending_i = -1

for name in entries:
	user_data = entries[name]
	score = user_data["score"]

	if score != maximum:
		continue
	if winner == None:
		winner = user_data
		defending_i = get_at_least_i(user_data, maximum)
		continue
	competing_i = get_at_least_i(user_data, maximum)

	if competing_i < defending_i:
		winner = user_data
		defending_i = competing_i
print(winner["name"])


d=dict()
l=[]
for i in range(int(input())):
    l+=[input().split()]
    try:
        d[l[i][0]]+=int(l[i][1])
    except KeyError:
        d[l[i][0]]=int(l[i][1])
d={k: v for k, v in sorted(d.items(), key=lambda item: item[1],reverse=True)}
maxi=max(d.values())
l1=[]
for i,j in d.items():
    if j==maxi:
        l1+=[i]

d=dict()
for i in l:
    try:
        d[i[0]]+=int(i[1])
    except KeyError:
        d[i[0]]=int(i[1])

    if d[i[0]]>=maxi and i[0] in l1:
        print(i[0])
        break


d=dict()
l=[]
for i in range(int(input())):
    l+=[input().split()]
    try:
        d[l[i][0]]+=int(l[i][1])
    except KeyError:
        d[l[i][0]]=int(l[i][1])
d={k: v for k, v in sorted(d.items(), key=lambda item: item[1],reverse=True)}
maxi=max(d.values())
l1=[]
for i,j in d.items():
    if j==maxi:
        l1+=[i]

d=dict()
for i in l:
    try:
        d[i[0]]+=int(i[1])
    except KeyError:
        d[i[0]]=int(i[1])

    if d[i[0]]==maxi and i[0] in l1:
        print(i[0])
        break


n=int(input())
d={}
max_score=0
max_name=""
for i in range(n):
    l=input().split()
    name=l[0]
    score=int(l[1])
    if name in d:
        d[name]+=score
    else:
        d[name]=score
    if d[name]>max_score:
        max_score=d[name]
        max_name=name
print(max_name)


n=int(input())
d={}
A=[]
for i in range(n):
    l=input().split()
    name=l[0]
    score=int(l[1])
    A.append([name,score])

for i in range(len(A)):
    name=A[i][0]
    score=A[i][1]
    if name in d:
        d[name][0]+=score
        d[name][1]=i
    else:
        d[name]=[score,i]
max_score=0
min_round=-1
max_name=""
for i in d:
    if d[i][0]>max_score:
        max_score=d[i][0]
        min_round=d[i][1]
        max_name=i
    elif d[i][0]==max_score:
        if d[i][1]<min_round:
            min_round=d[i][1]
            max_name=i
print(max_name)


n=int(input())
d={}
A=[]
for i in range(n):
    l=input().split()
    name=l[0]
    score=int(l[1])
    A.append([name,score])

for i in range(len(A)):
    name=A[i][0]
    score=A[i][1]
    if name in d:
        d[name]+=score
    else:
        d[name]=score

max_score=max(d.values())

d1={}
count=0
max_name=""
for i in d:
    if d[i]==max_score:
        max_name=i
        count+=1
        d1[i]=0
if count==1:
    print(max_name)
else:
    for i in range(len(A)):
        name=A[i][0]
        score=A[i][1]
        if name in d1:
            d1[name]+=score
            if d1[name]>=max_score:
                print(name)
                break


n=int(input())
d={}
A=[]
for i in range(n):
    l=input().split()
    name=l[0]
    score=int(l[1])
    A.append([name,score])

for i in range(len(A)):
    name=A[i][0]
    score=A[i][1]
    if name in d:
        d[name]+=score
    else:
        d[name]=score
max_score=max(d.values())
d1={}
for i in d:
    if d[i]==max_score:
        d1[i]=0
if len(d1)==1:
    for i in d:
        print(i)
        break
else:
    for i in range(len(A)):
        name=A[i][0]
        score=A[i][1]
        if name in d1:
            d1[name]+=score
            if d1[name]>=max_score:
                print(name)
                break


d={}
nmli=[]
for _ in range(int(input())):
    name,score=map(str,input().split())
    if name not in d:
        d[name]=0
    if int(score)>=0:
        nmli.append([name,int(score)])
        d[name]+=int(score)
    #print(int(score))

mx=-(10**9)
for i in d:
    mx=max(mx,d[i])
li=[]
ans=0
#print(d)
d2={}
for i in nmli:
    if i[0] not in d2:
        d2[i[0]]=0
    d2[i[0]]+=i[1]
    if(d2[i[0]]>=mx):
        print(i[0])
        break;
#print(d2)


d={}
nmli=[]
for _ in range(int(input())):
    name,score=map(str,input().split())
    if name not in d:
        d[name]=0
    #if int(score)>=0:
    nmli.append([name,int(score)])
    d[name]+=int(score)
    #print(int(score))

mx=-(10**9)
for i in d:
    mx=max(mx,d[i])
li=[]
ans=0
#print(d)
d2={}
for i in nmli:
    if i[0] not in d2:
        d2[i[0]]=0
    d2[i[0]]+=i[1]
    if(d2[i[0]]>=mx and d[i[0]]==mx):
        print(i[0])
        break;
#print(d2)


d={}
nmli=[]
for _ in range(int(input())):
    name,score=map(str,input().split())
    if name not in d:
        d[name]=0
    if int(score)>=0:
        nmli.append([name,int(score)])
        d[name]+=int(score)
    #print(int(score))

mx=-1001
for i in d:
    mx=max(mx,d[i])
li=[]
ans=0
d2={}
for i in nmli:
    if i[0] not in d2:
        d2[i[0]]=0
    d2[i[0]]+=i[1]
    if(d2[i[0]]==mx):
        print(i[0])
        break;
#print(d2)


d={}
nmli=[]
for _ in range(int(input())):
    name,score=map(str,input().split())
    if name not in d:
        d[name]=0

    nmli.append([name,int(score)])
    d[name]+=int(score)
mx=-1001
for i in d:
    mx=max(mx,d[i])
li=[]
ans=0
d2={}
for i in nmli:
    if i[0] not in d2:
        d2[i[0]]=0
    d2[i[0]]+=i[1]
    if(d2[i[0]]==mx):
        print(i[0])
        break;
#print(d2)


d={}
nmli=[]
for _ in range(int(input())):
    name,score=map(str,input().split())
    if name not in d:
        d[name]=0
    #if int(score)>=0:
    nmli.append([name,int(score)])
    d[name]+=int(score)
    #print(int(score))

mx=-(10**9)
for i in d:
    mx=max(mx,d[i])
li=[]
ans=0
#print(d)
d2={}
for i in nmli:
    if i[0] not in d2:
        d2[i[0]]=0
    d2[i[0]]+=i[1]
    if(d2[i[0]]>=mx):
        print(i[0])
        break;
#print(d2)


d={}
nmli=[]
for _ in range(int(input())):
    name,score=map(str,input().split())
    if name not in d:
        d[name]=0

    nmli.append([name,ord(score)-ord('0')])
    d[name]+=ord(score)-ord('0')
mx=-1001
for i in d:
    mx=max(mx,d[i])
li=[]
ans=0
d2={}
for i in nmli:
    if i[0] not in d2:
        d2[i[0]]=0
    d2[i[0]]+=i[1]
    if(d2[i[0]]==mx):
        print(i[0])
        break;
#print(d2)


n=int(input())
nl={}
e={}
nameslargest=[]
time=''
for i in range(n):
    N, S=input().split()
    time+=N
    if N in nl.keys():        nl[N]+=int(S)
    else:        nl[N]=int(S)
for name in nl.keys():
    e[name]=time.rfind(name)
m=max(nl.values())
for i in nl:
    if nl[i]==m:
        nameslargest+=[i]
for j in nameslargest:
    if e[j]==min(e.values()):
        print(j)


n=int(input())
nl={}
e={}
nameslargest=[]
time=''
for i in range(n):
    N, S=input().split()
    time+=N
    if N in nl.keys():        nl[N]+=int(S)
    else:        nl[N]=int(S)
for name in nl.keys():
    e[name]=time.rfind(name)
m=max(nl.values())
for i in nl:
    if nl[i]==m:
        nameslargest+=[i]
if len(nameslargest)==1:
    print(*nameslargest)
else:
    for j in nameslargest:
        if e[j]==min(e.values()):
            print(j)


p,r,n=[],{},int(input())
for i in range(n):
    a,b=input().split()
    b=int(b)
    r[a]=r.get(a,0)+b # if have a then +=b, else a=0
    p.append([r[a],a])
    m = max(r.values())
for n,a in p: # if givs the order (if r[a]>=m) and prints the inner "n,a"
    if n>=m and r[a]>=m:
        print(a)
        break


n = int(input())
xlis = []
for i in range(n):
    xlis.append(input().split())

dic = {}
for x in xlis:
    dic[x[0]] = dic.setdefault(x[0]) + int(x[1])

highscore = max(dic.values())
winnerlis = []
for x in dic:
    if dic[x] == highscore:
        winnerlis.append(x)

if len(winnerlis) == 1:
    print(winnerlis[0])
else:
    dic0 = {}
    for x in xlis:
        if x[0] in winnerlis:
            dic0[x[0]] = dic0.setdefault(x[0]) + int(x[1])
            if dic0[x[0]] >= highscore:
                print(x[0])
                break


n = int(input())

dic = {}
winlis = ['noname', 0]
for i in range(n):
    [name, score] = [_ for _ in input().split()]
    score = int(score)
    dic[name] = dic.setdefault(name, 0) + score
    if dic[name] > winlis[1]:
        winlis = [name, dic[name]]

print(winlis[0])


n = int(input())

dic = {}
winlis = [noname, 0]
for i in range(n):
    [name, score] = [_ for _ in input().split()]
    score = int(score)
    dic[name] = dic.setdefault(name, 0) + score
    if dic[name] > winlis[1]:
        winlis = [name, dic[name]]

print(winlis[0])


n = int(input())

dic = {}
winlis = ['noname', 0]
for i in range(n):
    [name, score] = [input().split()]
    score = int(score)
    dic[name] = dic.setdefault(name, 0) + score
    if dic[name] > winlis[1]:
        winlis = [name, dic[name]]

print(winlis[0])


n = int(input())
xlis = []
for i in range(n):
    xlis.append(input().split())

dic = {}
for x in xlis:
    dic[x[0]] = dic.setdefault(x[0], 0) + int(x[1])

highscore = max(dic.values())
winnerlis = []
for x in dic:
    if dic[x] == highscore:
        winnerlis.append(x)

if len(winnerlis) == 1:
    print(winnerlis[0])
else:
    dic0 = {}
    for x in xlis:
        if x[0] in winnerlis:
            dic0[x[0]] = dic0.setdefault(x[0], 0) + int(x[1])
            if dic0[x[0]] >= highscore:
                print(x[0])
                break


n = int(input())

dic = {}
winlis = [noname, 0]
for i in range(n):
    [name, score] = [input().split()]
    score = int(score)
    dic[name] = dic.setdefault(name, 0) + score
    if dic[name] > winlis[1]:
        winlis = [name, dic[name]]

print(winlis[0])


d = {}
m = 0
x = []
for i in range(int(input())):
    s = input().split()
    a, b = s[0], int(s[1])
    x.append((a, b))
    if a not in d:
        d[a] = 0
    d[a] += b
for a in d:
    if d[a] > m:
        m = d[a]
y = []
for i in d:
    if d[i] == m:
        y.append(i)
d = {}
for a, b in x:
    if a not in d:
        d[a] = 0
    d[a] += b
    if d[a] >= m and a in y:
        print(a)
        break


d = {}
m = [0, '']
for i in range(int(input())):
    s = input().split()
    a, b = s[0], int(s[1])
    if a not in d:
        d[a] = 0
    d[a] += b
    if m[1] == a:
        m[0] += b
    if d[a] > m[0]:
        m = [b, a]
print(m[1])


d = {}
m = [0, '']
for i in range(int(input())):
    s = input().split()
    a, b = s[0], int(s[1])
    if a not in d:
        d[a] = 0
    d[a] += b
    if m[1] == a:
        m = [d[a], a]
    if d[a] > m[0]:
        m = [b, a]
print(m[1])


d = {}
m = 0
x = []
for i in range(int(input())):
    s = input().split()
    a, b = s[0], int(s[1])
    x.append((a, b))
    if a not in d:
        d[a] = 0
    d[a] += b
    if d[a] > m:
        m = d[a]
y = []
for i in d:
    if d[i] == m:
        y.append(i)
d = {}
for a, b in x:
    if a not in d:
        d[a] = 0
    d[a] += b
    if d[a] == m and a in y:
        print(a)
        break


d = {}
m = 0
x = []
for i in range(int(input())):
    s = input().split()
    a, b = s[0], int(s[1])
    x.append((a, b))
    if a not in d:
        d[a] = 0
    d[a] += b
for i in d:
    if d[i] > m:
        m = d[i]
d = {}
for a, b in x:
    if a not in d:
        d[a] = 0
    d[a] += b
    if d[a] == m:
        print(a)
        break


d = {}
m = 0
x = []
for i in range(int(input())):
    s = input().split()
    a, b = s[0], int(s[1])
    x.append((a, b))
    if a not in d:
        d[a] = 0
    d[a] += b
    if d[a] > m:
        m = d[a]
d = {}
for a, b in x:
    if a not in d:
        d[a] = 0
    d[a] += b
    if d[a] == m:
        print(a)
        break


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n
for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key
        for i, j in value[3]:

            if value[0] <= i:
                naan = j
                break

    elif value[0] == d[max_name][0]:
        for i, j in value[3]:
            if d[max_name][0] <= i:
                if j < naan:
                    naan = j
                    max_name = key
                break

print(max_name)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n

for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key
    elif value[0] == d[max_name][0]:
        for i, j in value[0][3]:
            if d[max_name][0] <= i:
                if j < n:
                    max_name = key
                break

print(max_name)


d = {}
max_score = 0
max_name = ""
for _ in range(int(input())):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = score

    else:
        d[name] += score

    if d[name] > max_score:
        max_score = d[name]
        max_name = name

maxxx = 0
x = 0
for key, value in d.items():
    if value > maxxx:
        maxxx= value
        x = key
if maxxx == max_score:
    print(max_name)
else:
    print(x)


d = {}
max_score = 0
max_name = "zebommek"
d[max_name] = [0, -1]
for i in range(int(input())):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, i]

    else:
        d[name][0] += score
        d[name][1] = i

    if d[name][0] > d[max_name][0]:
        max_name = name
for key, value in d.items():
    if value[0] >= d[max_name][0] and value[1] < d[max_name][1]:
        max_name = key

print(max_name)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n
for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key
        for i, j in value[3]:
            if d[max_name][0] <= i:
                naan = j

    elif value[0] == d[max_name][0]:
        for i, j in value[3]:
            if d[max_name][0] <= i:
                if j < naan:
                    max_name = key
                break

print(max_name)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n]

for key, value in d.items():
    if value[0] > d[max_name][0] or (value[0] == d[max_name][0] and value[2] < d[max_name][2]):
        max_name = key

print(max_name)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n
for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key

        for i, j in value[3]:
            if value[0] <= i:
                naan = j

    elif value[0] == d[max_name][0]:
        for i, j in value[3]:
            if d[max_name][0] <= i:
                if j < naan:
                    max_name = key
                break

print(max_name)


d = {}
max_score = 0
max_name = ""
for _ in range(int(input())):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = score

    else:
        d[name] += score

    if d[name] > max_score:
        max_score = d[name]
        max_name = name

x = max(d)
if d[x] == max_score:
    print(max_name)
else:
    print(x)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n
for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key
    elif value[0] == d[max_name][0]:
        for i, j in value[3]:
            if d[max_name][0] <= i:
                if j < n:
                    max_name = key
                break

print(max_name)


d = {}
max_score = 0
max_name = ""
for _ in range(int(input())):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = score

    else:
        d[name] += score

    if d[name] > max_score:
        max_score += d[name]
        max_name = name

print(max_name)


d = {}
max_score = 0
max_name = "zebommek"
d[max_name] = 0
for _ in range(int(input())):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = score

    else:
        d[name] += score

    if d[name] > d[max_name]:
        max_name = name
print(max_name)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n
for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key

        for i, j in value[3]:
            if d[value][0] <= i:
                naan = j

    elif value[0] == d[max_name][0]:
        for i, j in value[3]:
            if d[max_name][0] <= i:
                if j < naan:
                    max_name = key
                break

print(max_name)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n
for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key

        for i, j in value[3]:
            if value[0] <= i:
                naan = j

    elif value[0] == d[max_name][0]:
        for i, j in value[3]:
            if d[max_name][0] <= i:
                if j < naan:
                    naan = j
                    max_name = key
                break

print(max_name)


d = {}
n = int(input())
for i in range(n):

    name, score = input().split()
    score = int(score)
    if name not in d.keys():
        d[name] = [score, score, i, [[score, i]]]

    else:
        if d[name][0] + score > d[name][1]:
            d[name][1] = d[name][0] + score
            d[name][2] = i
            d[name][3].append([d[name][0] + score, i])
        d[name][0] += score

max_name = "zebommek"
d[max_name] = [-1, -1, n, [-1, n]]
naan = n
for key, value in d.items():
    if value[0] > d[max_name][0]:
        max_name = key
        for i, j in value[3]:
            if d[max_name][0] <= i:
                naan = j

    elif value[0] == d[max_name][0]:
        for i, j in value[3]:
            if d[max_name][0] <= i:
                if j < naan:
                    max_name = key
                    print(max_name)
                break

print(max_name)


from math import inf
n = int(input())
rounds = []
for i in range(n):
    a,b = input().split()
    rounds.append([a,int(b)])
tot_scores = {}
for i in range(n):
    move = rounds[i]
    tot_scores[move[0]] = tot_scores.get(move[0],0) + move[1]
m = -inf
for player in tot_scores:
    m = max(m, tot_scores[player])
pos_winners = set()
for player in tot_scores:
    if tot_scores[player] == m:
        pos_winners.add(player)
scores = {}
for i in range(n):
    move = rounds[i]
    scores[move[0]] = scores.get(move[0],0) + move[1]
    if scores[move[0]] >= m and move[0] in pos_winners:
        print(move[0])
        break


from math import inf
n = int(input())
rounds = []
for i in range(n):
    a,b = input().split()
    rounds.append([a,int(b)])
tot_scores = {}
for i in range(n):
    move = rounds[i]
    tot_scores[move[0]] = tot_scores.get(move[0],0) + move[1]
m = -inf
for player in tot_scores:
    m = max(m, tot_scores[player])
scores = {}
for i in range(n):
    move = rounds[i]
    scores[move[0]] = scores.get(move[0],0) + move[1]
    if scores[move[0]] >= m:
        print(move[0])
        break


from math import inf
n = int(input())
rounds = []
for i in range(n):
    a,b = input().split()
    rounds.append([a,int(b)])
tot_scores = {}
for i in range(n):
    move = rounds[i]
    tot_scores[move[0]] = tot_scores.get(move[0],0) + move[1]
m = -inf
for player in tot_scores:
    m = max(m, tot_scores[player])
scores = {}
for i in range(n):
    move = rounds[i]
    scores[move[0]] = scores.get(move[0],0) + move[1]
    if scores[move[0]] == m:
        print(move[0])
        break


n = int(input())
rounds = []
for i in range(n):
    a,b = input().split()
    rounds.append([a,int(b)])
m = max(rounds, key = lambda x: x[1])[1]
scores = {}
for i in range(n):
    move = rounds[i]
    scores[move[0]] = scores.get(move[0],0) + move[1]
    if scores[move[0]] == m:
        print(move[0])
        break


ar=[];d={}
for _ in range(int(input())):
    a,b=input().split()
    d[a]=d.get(a,0)+int(b)
    ar.append([a,d[a]])
max1=max(d.values())
for i, j in ar:
    if d[i]==max1 and j==max1:
        print(i)
        break


ar=[];d={}
for _ in range(int(input())):
    a,b=input().split()
    d[a]=d.get(a,0)+int(b)
    ar.append([a,d[a]])
max1=max(d.values())
for i, j in ar:
    if d[i]==m:
        print(i)
        break


ar=[];d={}
for _ in range(int(input())):
    a,b=input().split()
    d[a]=d.get(a,0)+int(b)
    ar.append([a,d[a]])
max1=max(d.values())
for i, j in ar:
    if d[i]==max1 and j>=max1:
        print(i)
        break


d=dict()
for _ in range(int(input())):
    a,b=map(str,input().split())
    b=int(b)
    if a in d:
        if b>=0:
            d[a]+=b
        else:
            d[a]-=b
    else:
            d[a]=b
v=list(sorted(d.values()))
k=list(sorted(d.keys()))
print(k[v.index(max(v))])


d=dict()
for _ in range(int(input())):
    a,b=map(str,input().split())
    b=int(b)
    if a in d:
        d[a]+=b
    else:
        d[a]=b
v=list(sorted(d.values()))
k=list(sorted(d.keys()))
print(k[v.index(max(v))])


d=dict()
for _ in range(int(input())):
    a,b=map(str,input().split())
    b=int(b)
    if a in d:
        d[a]+=b
    else:
        if b>0:
            d[a]=b
v=list(sorted(d.values()))
k=list(sorted(d.keys()))
print(k[v.index(max(v))])


n = int(input())
d = {}
d2 = {}
for i in range(n):
    name, x = input().split()
    x = int(x)
    if name not in d:
        d[name] = [x, i]
        d2[name] = [x, i]
    else:
        d[name] = [d[name][0] + x, i]
        if d[name][0] > d2[name][0]:
            d2[name] = d[name]

def k1(x):
    return -x[1][0]

def k2(x):
    return x[1][1]

kip = list(d2.items())
kip.sort(key=k2)
kip.sort(key=k1)
print(kip[0][0])


n = int(input())
d = {}
sc = {}
for i in range(n):
    name, x = input().split()
    x = int(x)
    if name not in d:
        d[name] = x
    else:
        d[name] += x

    if d[name] not in sc:
        sc[d[name]] = name
    if d[name] > d[sc[d[name]]]:
        sc[d[name]] = name

ma = max(d.values())
print(sc[ma])


n = int(input())
d = {}
ma = -(10**18)
mn = ''
for zz in range(n):
    name, x = input().split()
    x = int(x)
    if name not in d:
        d[name] = 0
    d[name] += x
    if d[name] > ma:
        mn = name
        ma = d[name]
print(mn)


n = int(input())
d = {}
sc = {}
for i in range(n):
    name, x = input().split()
    x = int(x)
    if name not in d:
        d[name] = x
    else:
        d[name] += x

    if d[name] not in sc:
        sc[d[name]] = name

ma = max(d.values())
print(sc[ma])


n = int(input())
cw = ''
d = {}

for i in range(n):
    a, b = input().split()
    b = int(b)
    if a in d:
        d[a].append([d[a][-1][0] + b, i])
    else:
        d[a] = [[b, i]]

ma = -10**20
mi = ''
for k in d:
    if d[k][-1][0] > ma:
        ma = d[k][-1][0]
        mi = k
    elif d[k][-1][0] == ma:
        x = len(d[k])
        y = len(d[mi])
        i1 = 2000
        for z in range(x):
            if d[k][z][0] >= ma:
                i1 = d[k][z][1]
                break
        i2 = 2000
        for z in range(y):
            if d[mi][z][0] >= ma:
                i2 = d[mi][z][1]
                break

        if i1 < i2:
            mi = k
        #print(i1, i2, k)

print(mi)


from collections import defaultdict
from functools import reduce

def main():
    n = int(input())
    m = defaultdict(int)
    ma = 0
    l = []
    for i in range(n):
        s = input().split(' ')
        l.append((s[0], int(s[1])))
        m[s[0]] += int(s[1])
        ma = max(m[s[0]], ma)

    m = defaultdict(int)
    for i in range(n):
        s = l[i]
        m[s[0]] += s[1]
        if m[s[0]] == ma:
            return s[0]
    return "??"
print(main())


from collections import defaultdict
from functools import reduce

def main():
    n = int(input())
    m = defaultdict(int)
    ma = 0
    l = []
    for i in range(n):
        s = input().split(' ')
        l.append((s[0], int(s[1])))
        m[s[0]] += int(s[1])

    winners = set()
    ma = max(m.values())
    m = defaultdict(int)
    for i in range(n):
        m[l[i][0]] += l[i][1]
        if m[l[i][0]] >= ma:
            return l[i][0]

    return "??"
print(main())


from collections import defaultdict
from functools import reduce

def main():
    n = int(input())
    m = defaultdict(int)
    ma = 0
    l = []
    for i in range(n):
        s = input().split(' ')
        l.append((s[0], int(s[1])))
        m[s[0]] += int(s[1])
        ma = max(m[s[0]], ma)

    m = defaultdict(int)
    for i in range(n):
        s = l[i]
        m[s[0]] += s[1]
        if m[s[0]] >= ma:
            return s[0]
    return "??"
print(main())


from collections import defaultdict
from functools import reduce

def main():
    n = int(input())
    m = defaultdict(int)
    ma = 0
    l = []
    for i in range(n):
        s = input().split(' ')
        l.append((s[0], int(s[1])))
        m[s[0]] += int(s[1])

    winners = set()
    ma = max(m.values())
    for i in range(n):
        m[l[i][0]] += l[i][1]
        if m[l[i][0]] >= ma:
            return l[i][0]

    return "??"
print(main())


from collections import defaultdict
from functools import reduce

def main():
    n = int(input())
    m = defaultdict(int)
    ma = 0
    l = []
    for i in range(n):
        s = input().split(' ')
        l.append((s[0], int(s[1])))
        m[s[0]] += int(s[1])
        ma = max(m[s[0]], ma)

    se = set()
    m = defaultdict(int)
    for i in range(n):
        s = l[i]
        m[s[0]] += s[1]
        if m[s[0]] >= ma:
            se.add(s[0])

    m = defaultdict(int)
    for i in range(n):
        s = l[i]
        if s[0] not in se:
            continue
        m[s[0]] += s[1]
        if m[s[0]] >= ma:
            return s[0]
    return "??"
print(main())


from collections import defaultdict
from functools import reduce

def main():
    n = int(input())
    m = defaultdict(int)
    ma = 0
    l = []
    for i in range(n):
        s = input().split(' ')
        l.append((s[0], int(s[1])))
        m[s[0]] += int(s[1])
        ma = max(m[s[0]], ma)

    se = set()
    m = defaultdict(int)
    for i in range(n):
        s = l[i]
        m[s[0]] += s[1]
        if m[s[0]] == ma:
            se.add(s[0])

    m = defaultdict(int)
    for i in range(n):
        s = l[i]
        if s[0] not in se:
            continue
        m[s[0]] += s[1]
        if m[s[0]] >= ma:
            return s[0]

    return "??"
print(main())


from collections import defaultdict
from functools import reduce

def main():
    n = int(input())
    m = defaultdict(int)
    ma = 0
    l = []
    for i in range(n):
        s = input().split(' ')
        l.append((s[0], int(s[1])))
        m[s[0]] += int(s[1])

    winners = set()
    ma = max(m.values())
    m = defaultdict(int)
    for i in range(n):
        m[l[i][0]] += l[i][1]
        if m[l[i][0]] == ma:
            winners.add(l[i][0])

    if len(winners) == 1:
        return list(winners)[0]

    m = defaultdict(int)
    for i in range(n):
        m[l[i][0]] += l[i][1]
        if m[l[i][0]] >= ma and l[i][0] in winners:
            return l[i][0]

    return "??"
print(main())


people = {}

inputs = []

for i in range(int(input())):
	name, delta = input().split()
	delta = int(delta)

	inputs.append((name, delta))

	if name not in people.keys():
		people[name] = 0

	people[name] += delta

m = max(people.values())

candidates = []
for i in people.keys():
	if people[i] == m:
		candidates.append(i)

if len(candidates) == 1:
	print(candidates[0])
else:
	for i in people.keys():
		people[i] = 0

	for name, delta in inputs:
		people[name] += delta

		if people[name] >= m:
			print(name)
			exit()


people = {}

inputs = []

for i in range(int(input())):
	name, delta = input().split()
	delta = int(delta)

	inputs.append((name, delta))

	if name not in people.keys():
		people[name] = 0

	people[name] += delta

m = max(people.values())

candidates = []
for i in people.keys():
	if people[i] == m:
		candidates.append(i)

if len(candidates) == 1:
	print(candidates[0])
else:
	for i in people.keys():
		people[i] = 0

	for name, delta in inputs:
		people[name] += delta

		if people[name] >= m and name in candidates:
			print(name)
			exit()


people = {}

for i in range(int(input())):
	name, delta = input().split()
	delta = int(delta)

	if name not in people.keys():
		people[name] = (0, 0)

	people[name] = (people[name][0] + delta, i)

values = people.values()
values = sorted(values, key = lambda x: (-x[0], x[1]))

ans_val = values[0]

for k in people.keys():
	if people[k] == ans_val:
		print(k)
		exit()


n = int(input())
ap = {}
lst = []
for i in range(n):
    x , y = map(str , input().split())
    try:
        t = ap[x]
    except:
        ap[x] = int(y)
    else:
        ap[x] += int(y)
        y = ap[x]
    lst.append([x, int(y)])
cur = -10001
ans = ""
cnt = -10001
lk = []
for i in range(n):
    if (ap[lst[i][0]] > cnt):
        cnt = ap[lst[i][0]]
for i in range(n):
    if (ap[lst[i][0]] == cnt and lst[i][0] not in lk):
        lk.append(lst[i][0])
for i in range(n):
    if lst[i][1]>cur and (lst[i][0] in lk):
        ans = lst[i][0]
        cur = lst[i][1]
print(ans)


n = int(input())
ap = {}
lst = []
for i in range(n):
    x , y = map(str , input().split())
    try:
        t = ap[x]
    except:
        ap[x] = int(y)
    else:
        ap[x] += int(y)
        y = ap[x]
    lst.append([x, int(y)])
cur = -10001
ans = ""
for i in range(n):
    if lst[i][1]>cur:
        ans = lst[i][0]
        cur = lst[i][1]
print(ans)


n = int(input())
ap = {}
lst = []
for i in range(n):
    x , y = map(str , input().split())
    try:
        t = ap[x]
    except:
        ap[x] = int(y)
    else:
        ap[x] += int(y)
    lst.append(x)
lst.sort()
lst.reverse()
cur = -10001
ans = ""
for i in range(n):
    if (ap[lst[i]]>=cur):
        ans = lst[i]
        cur = ap[lst[i]]
print(ans)


n = int(input())
ap = {}
lst = []
for i in range(n):
    x , y = map(str , input().split())
    try:
        t = ap[x]
    except:
        ap[x] = int(y)
    else:
        ap[x] += int(y)
        y = ap[x]
    lst.append([x, int(y)])
cur = -10001
ans = ""
cnt = -10001
lk = []
for i in range(n):
    if (ap[lst[i][0]] > cnt):
        cnt = ap[lst[i][0]]
for i in range(n):
    if (ap[lst[i][0]] == cnt):
        lk.append(lst[i][0])
for i in range(n):
    if lst[i][1]>cur and lst[i][0] in lk:
        ans = lst[i][0]
        cur = lst[i][1]
print(ans)


n = int(input())
ap = {}
lst = []
for i in range(n):
    x , y = map(str , input().split())
    try:
        t = ap[x]
    except:
        ap[x] = int(y)
    else:
        ap[x] += int(y)
        y = ap[x]
    lst.append([x, int(y)])
cur = -10001
ans = ""
cnt = -10001
lk = []
for i in range(n):
    if (ap[lst[i][0]] > cnt):
        cnt = ap[lst[i][0]]
for i in range(n):
    if (ap[lst[i][0]] == cnt and lst[i][0] not in lk):
        lk.append(lst[i][0])
for i in range(n):
    if lst[i][1]>=cnt:
        print(lst[i][0])
        break


n = int(input())
ap = {}
lst = []
for i in range(n):
    x , y = map(str , input().split())
    try:
        t = ap[x]
    except:
        ap[x] = int(y)
    else:
        ap[x] += int(y)
    lst.append(x)
lst.sort()
cur = -10001
ans = ""
for i in range(n):
    if (ap[lst[i]]>cur):
        ans = lst[i]
        cur = ap[lst[i]]
print(ans)


n = int(input())
ap = {}
lst = []
for i in range(n):
    x , y = map(str , input().split())
    try:
        t = ap[x]
    except:
        ap[x] = int(y)
    else:
        ap[x] += int(y)
        y = ap[x]
    lst.append([x, int(y)])
cur = -10001
ans = ""
cnt = -10001
lk = []
for i in range(n):
    if (ap[lst[i][0]] > cnt):
        cnt = ap[lst[i][0]]
for i in range(n):
    if (ap[lst[i][0]] == cnt and lst[i][0] not in lk):
        lk.append(lst[i][0])
for i in range(n):
    if lst[i][1]>=cnt and lst[i][0] in lk:
        print(lst[i][0])
        break


n = int(input())
d = {}
li = []
for i in range(n):
    n, p = map(str, input().split())
    d[n] = d.get(n, 0) + int(p)
    li.append([n, p])
maxm = 0
count = 0
for x in d:
    if d[x] == maxm:
        count += 1
    elif d[x] > maxm:
        count = 1
        maxm = d[x]
ans = ""
pt = {}
for x, y in li:
    pt[x] = pt.get(x, 0) + int(y)
    if pt[x] == maxm:
        ans = x
        break
print(ans)


n = int(input())
d = {}
li = []
max_arr={}
for i in range(n):
    na, p = map(str, input().split())
    d[na] = d.get(na, 0) + int(p)
    li.append([na, p])
maxm = max(d.values())
ans = ""
dp = {}
for x, y in li:
    dp[x] = dp.get(x, 0) + int(y)
    if dp[x] >= maxm:
        ans = x
        break
print(ans)


n = int(input())
d = {}
li = []
max_arr={}
for i in range(n):
    na, p = map(str, input().split())
    d[na] = d.get(na, 0) + int(p)
    li.append([na, p])
maxm = max(d.values())
ans = ""
dp = {}
for x, y in li:
    dp[x] = dp.get(x, 0) + int(y)
    if dp[x] >= maxm and d[x] == maxm:
        ans = x
        break
print(ans)


from operator import itemgetter
n = int(input())
ai =  [input().split() + [i] for i in range(n)]
for i in range(n):
    ai[i][1] = int(ai[i][1])
ai.sort(key = itemgetter(0))
ans = ai[0][0]
maxi = int(ai[0][1])
maxi2 = ai[0][2]
flag = 0
for i in range(1,n):
    if ai[i][0] == ai[i-1][0]:
         ai[i][1] = int(ai[i][1]) + int(ai[i-1][1])
    else:
        if maxi < int(ai[i-1][1]):
            maxi = int(ai[i-1][1])
            maxi2 = ai[i-1][2]
            ans = ai[i-1][0]
        elif maxi == int(ai[i-1][1]) and maxi2 > ai[i-1][2]:
            flag = 1
if maxi < int(ai[n-1][1]):
    maxi = ai[n-1][1]
    ans = ai[n-1][0]
elif maxi == int(ai[n-1][1]) and maxi2 > ai[n-1][2]:
        flag = 1
maxi3 = n
if flag == 1:
    for i in range(n):
        if int(ai[i-1][1]) >= maxi:
            if maxi3 > ai[i-1][2]:
                ans = ai[i-1][0]
                maxi3 = ai[i-1][2]
print(ans)


from operator import itemgetter
n = int(input())
ai =  [input().split() + [i] for i in range(n)]
for i in range(n):
    ai[i][1] = int(ai[i][1])
ai.sort(key = itemgetter(0))
ans = ai[0][0]
maxi = int(ai[0][1])
flag = 0
ans2 = [ai[0][0]]
for i in range(1,n):
    if ai[i][0] == ai[i-1][0]:
         ai[i][1] = int(ai[i][1]) + int(ai[i-1][1])
    else:
        if maxi < int(ai[i-1][1]):
            maxi = int(ai[i-1][1])
            ans = ai[i-1][0]
            ans2 = [ai[i-1][0]]
            flag = 0
        elif maxi == int(ai[i-1][1]) :
            ans2 += [ai[i-1][0]]
            flag = 1
if maxi < int(ai[n-1][1]):
    maxi = ai[n-1][1]
    ans = ai[n-1][0]
    ans2 = [ai[i-1][0]]
    flag = 0
elif maxi == int(ai[n-1][1]):
    ans2 += [ai[i-1][0]]
    flag = 1
maxi3 = n
if flag == 1:
    for i in range(n):
        if int(ai[i-1][1]) >= maxi and ai[i-1][0] in  ans2:
            if maxi3 > ai[i-1][2]:
                ans = ai[i-1][0]
                maxi3 = ai[i-1][2]
print(ans)


from operator import itemgetter
n = int(input())
dic =  [input().split() + [i] for i in range(n)]
dic.sort(key = itemgetter(0))
ans = dic[0][0]
maxi = int(dic[0][1])
maxi2 = dic[0][2]
for i in range(1,n):
    if dic[i][0] == dic[i-1][0]:
         dic[i][1] = int(dic[i][1]) + int(dic[i-1][1])
    else:
        if maxi < int(dic[i-1][1]):
            maxi = int(dic[i-1][1])
            maxi2 = dic[i-1][2]
            ans = dic[i-1][0]
        elif maxi == int(dic[i-1][1]) and maxi2 > dic[i-1][2]:
            ans = dic[i-1][0]
            maxi2 = dic[i-1][2]
if maxi < int(dic[n-1][1]):
    maxi = dic[n-1][1]
    ans = dic[n-1][0]
elif maxi == int(dic[n-1][1]) and maxi2 > dic[n-1][2]:
        ans = dic[n-1][0]
        maxi2 = dic[n-1][2]
print(ans)


from operator import itemgetter
n = int(input())
ai =  [input().split() + [i] for i in range(n)]
for i in range(n):
    ai[i][1] = abs(int(ai[i][1]))
ai.sort(key = itemgetter(0))
ans = ai[0][0]
maxi = int(ai[0][1])
maxi2 = ai[0][2]
for i in range(1,n):
    if ai[i][0] == ai[i-1][0]:
         ai[i][1] = int(ai[i][1]) + int(ai[i-1][1])
    else:
        if maxi < int(ai[i-1][1]):
            maxi = int(ai[i-1][1])
            maxi2 = ai[i-1][2]
            ans = ai[i-1][0]
        elif maxi == int(ai[i-1][1]) and maxi2 > ai[i-1][2]:
            ans = ai[i-1][0]
            maxi2 = ai[i-1][2]
if maxi < int(ai[n-1][1]):
    maxi = ai[n-1][1]
    ans = ai[n-1][0]
elif maxi == int(ai[n-1][1]) and maxi2 > ai[n-1][2]:
        ans = ai[n-1][0]
        maxi2 = ai[n-1][2]
print(ans)


from operator import itemgetter
n = int(input())
ai =  [input().split() + [i] for i in range(n)]
for i in range(n):
    ai[i][1] = int(ai[i][1])
ai.sort(key = itemgetter(0))
ans = ai[0][0]
maxi = int(ai[0][1])
flag = 0
for i in range(1,n):
    if ai[i][0] == ai[i-1][0]:
         ai[i][1] = int(ai[i][1]) + int(ai[i-1][1])
    else:
        if maxi < int(ai[i-1][1]):
            maxi = int(ai[i-1][1])
            ans = ai[i-1][0]
            flag = 0
        elif maxi == int(ai[i-1][1]) :
            flag = 1
if maxi < int(ai[n-1][1]):
    maxi = ai[n-1][1]
    ans = ai[n-1][0]
    flag = 0
elif maxi == int(ai[n-1][1]):
        flag = 1
maxi3 = n
if flag == 1:
    for i in range(n):
        if int(ai[i-1][1]) >= maxi:
            if maxi3 > ai[i-1][2]:
                ans = ai[i-1][0]
                maxi3 = ai[i-1][2]
print(ans)


from operator import itemgetter
n = int(input())
ai =  [input().split() + [i] for i in range(n)]
for i in range(n):
    ai[i][1] = int(ai[i][1])
ai.sort(key = itemgetter(0))
ans = ai[0][0]
maxi = int(ai[0][1])
maxi2 = ai[0][2]
for i in range(1,n):
    if ai[i][0] == ai[i-1][0]:
         ai[i][1] = int(ai[i][1]) + int(ai[i-1][1])
    else:
        if maxi < int(ai[i-1][1]):
            maxi = int(ai[i-1][1])
            maxi2 = ai[i-1][2]
            ans = ai[i-1][0]
        elif maxi == int(ai[i-1][1]) and maxi2 > ai[i-1][2]:
            ans = ai[i-1][0]
            maxi2 = ai[i-1][2]
if maxi < int(ai[n-1][1]):
    maxi = ai[n-1][1]
    ans = ai[n-1][0]
elif maxi == int(ai[n-1][1]) and maxi2 > ai[n-1][2]:
        ans = ai[n-1][0]
        maxi2 = ai[n-1][2]
maxi3 = n-1
for i in range(n):
    if int(ai[i-1][1]) >= maxi:
        if maxi3 > ai[i-1][2]:
            ans = ai[i-1][0]
            maxi3 = ai[i-1][2]
print(ans)


from operator import itemgetter
n = int(input())
ai =  [input().split() + [i] for i in range(n)]
for i in range(n):
    ai[i][1] = int(ai[i][1])
ai.sort(key = itemgetter(0))
ans = ai[0][0]
maxi = int(ai[0][1])
for i in range(1,n):
    if ai[i][0] == ai[i-1][0]:
         ai[i][1] = int(ai[i][1]) + int(ai[i-1][1])
    else:
        maxi = max(maxi,int(ai[i-1][1]))
maxi = max(maxi,int(ai[n-1][1]))

maxi3 = n
for i in range(n):
    if int(ai[i-1][1]) >= maxi:
        if maxi3 > ai[i-1][2]:
            ans = ai[i-1][0]
            maxi3 = ai[i-1][2]
print(ans)


from operator import itemgetter
n = int(input())
ai =  [input().split() + [i] for i in range(n)]
for i in range(n):
    ai[i][1] = int(ai[i][1])
ai.sort(key = itemgetter(0))
ans = ai[0][0]
maxi = int(ai[0][1])
flag = 0
for i in range(1,n):
    if ai[i][0] == ai[i-1][0]:
         ai[i][1] = int(ai[i][1]) + int(ai[i-1][1])
    else:
        if maxi < int(ai[i-1][1]):
            maxi = int(ai[i-1][1])
            ans = ai[i-1][0]
        elif maxi == int(ai[i-1][1]) :
            flag = 1
if maxi < int(ai[n-1][1]):
    maxi = ai[n-1][1]
    ans = ai[n-1][0]
elif maxi == int(ai[n-1][1]):
        flag = 1
maxi3 = n
if flag == 1:
    for i in range(n):
        if int(ai[i-1][1]) >= maxi:
            if maxi3 > ai[i-1][2]:
                ans = ai[i-1][0]
                maxi3 = ai[i-1][2]
print(ans)


d={}
nn=''
n=int(input())
for i in range(n):
	nm,p = input().split(' ')
	p=int(p)
	if(nm in d):
		nn=nm
		d[nm][0]+=p
		d[nm][1]=i
	else:
		d[nm]=[p,i]

mx=d[nn][0]
for nm in d.keys():
	if(d[nm][0]>mx):
		mx=d[nm][0]

ind=n
ans=''
for nm in d.keys():
	if(d[nm][0]==mx and d[nm][1]<i):
		ind=i
		ans=nm

print(ans)


d={}
nn=''

l=[]
n=int(input())
for i in range(n):
	nm,p = input().split(' ')
	p=int(p)
	l.append([nm,p])
	if(nm in d):
		nn=nm
		d[nm][0]+=p
		d[nm][1]=i
	else:
		d[nm]=[p,i]

mx=d[nn][0]
for nm in d.keys():
	if(d[nm][0]>=mx):
		mx=d[nm][0]

ans=''
dd=dict({(x,0) for x in d.keys()})
for nm,p in l:
	dd[nm]+=p
	if(dd[nm]>=mx):
		ans=nm
		break

print(ans)


d={}
nn=''

l=[]
n=int(input())
for i in range(n):
	nm,p = input().split(' ')
	p=int(p)
	l.append([nm,p])
	if(nm in d):
		nn=nm
		d[nm][0]+=p
		if(p<0):
			d[nm][1]=i
	else:
		d[nm]=[p,i]

mx=d[nn][0]
for nm in d.keys():
	if(d[nm][0]>=mx):
		mx=d[nm][0]

dd={}

for nm in d.keys():
	if(d[nm][0]==mx):
		dd[nm]=0

ans=''
for nm,p in l:
	if(nm in dd):
		dd[nm]+=p
		if(dd[nm]>=mx):
			ans=nm
			break

'''
ind=n
ans=''
for nm in d.keys():
	if(d[nm][0]==mx and d[nm][1]<ind):
		ind = d[nm][1]
		ans=nm
'''

print(ans)


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair< ll, ll > ii;
typedef vector< ll > vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s))
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

#define pi acos(-1.0)

struct Point {
  ll x, y;
  Point(){};
  Point(ll _x, ll _y) {
    x = _x;
    y = _y;
  }
  void read(){
    double _x, _y;
    scanf("%lf %lf", &_x, &_y);
    x = _x;
    y = _y;
  }
  ll operator % (Point other) { return x * other.y - other.x * y; }
  ll operator * (Point other) { return x * other.x + y * other.y; }
  Point operator * (double t) { return Point(x * t, y * t); }
  Point operator - (Point other) { return Point(x - other.x, y - other.y); }
  Point operator + (Point other) { return Point(x + other.x, y + other.y); }
  ld norm() { return sqrt(x * x + y * y); }
  ld distToPoint(Point other) {
    return hypot(other.y - y, other.x - x);
  }
};

const int N = 501;

int n, m;
Point bd[N], rd[N];
int pd[N][N];

int main() {
  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; ++i) rd[i].read();
  for(int i = 0; i < m; ++i) bd[i].read();
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < n; ++j) {
      if(rd[i].x >= rd[j].x) continue;
      for(int k = 0; k < m; ++k) {
        if(rd[i].x <= bd[k].x && bd[k].x < rd[j].x) pd[i][j] += ((rd[i] - bd[k]) % (rd[j] - bd[k])) >= 0;
      }
      pd[j][i] = -pd[i][j];
    }
  }
  int sol = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      for(int k = j + 1; k < n; ++k) {
        sol += ((pd[i][j] + pd[j][k] + pd[k][i]) == 0);
      }
    }
  }
  printf("%d\n", sol);
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair< ll, ll > ii;
typedef vector< ll > vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s))
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

#define pi acos(-1.0)

struct Point {
  ll x, y;
  Point(){
    x = rand() % 1000000 + 1;
    y = rand() % 1000000 + 1;
  };
  Point(ll _x, ll _y) {
    x = _x;
    y = _y;
  }
  void read(){
    double _x, _y;
    scanf("%lf %lf", &_x, &_y);
    x = _x;
    y = _y;
  }
  ll operator % (Point other) { return x * other.y - other.x * y; }
  ll operator * (Point other) { return x * other.x + y * other.y; }
  Point operator * (double t) { return Point(x * t, y * t); }
  Point operator - (Point other) { return Point(x - other.x, y - other.y); }
  Point operator + (Point other) { return Point(x + other.x, y + other.y); }
  ld norm() { return sqrt(x * x + y * y); }
  ld distToPoint(Point other) {
    return hypot(other.y - y, other.x - x);
  }
};

const int N = 501;

int n, m;
Point bd[N], rd[N];
bitset<N> me[N][N], md[N][N];

int main() {
  srand(time(NULL));
  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; ++i) rd[i].read();
  for(int i = 0; i < m; ++i) bd[i].read();
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      bitset<N> all; all[0] = 1;
      for(int k = 0; k < m; ++k) {
        bool yes = ((rd[i] - bd[k]) % (rd[j] - bd[k])) >= 0;
        if(!yes) me[i][j] |= all;
        else md[i][j] |= all;
        if(yes) me[j][i] |= all;
        else md[j][i] |= all;
        all <<= 1;
      }
    }
  }

  int sol = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      for(int k = j + 1; k < n; ++k) {
        bitset<N>ae = (me[i][j] & me[j][k] & me[k][i]);
        bitset<N>ad = (md[i][j] & md[j][k] & md[k][i]);
        ll esq = ae.count();
        ll dir = ad.count();
        sol += (esq == 0 && dir == 0);
      }
    }
  }
  printf("%d\n", sol);
  return 0;
}