#include <iostream>

using namespace std;

class Node {
public:
    Node* next;
    int id;
    Node(int id, Node* next) : id(id), next(next) {}
    
};

Node* FindLoopBegin(Node *head) {
    Node *slowptr = head,*fastptr = head;
    bool LoopExists = false;
    while(slowptr && fastptr){
        fastptr = fastptr->next;
        //if(fastptr == slowptr) {LoopExists = true;break;}
        if(fastptr == NULL) {LoopExists = false; return NULL;}
        fastptr = fastptr->next;
        slowptr = slowptr->next;
        if(fastptr == slowptr) {LoopExists = true;break;}
    }
    if(LoopExists) {
        slowptr = head;
        while(slowptr != fastptr){
            slowptr = slowptr->next;
            fastptr = fastptr->next;
        }
        return slowptr;
    }   
    return NULL;
}

int main()
{
   Node* n10 = new Node(10,NULL);
   Node* n12 = new Node(12,NULL);
   Node* n14 = new Node(14,NULL);
   n12->next = n14;
   n14->next = n12;
   n10->next = n12;
   cout<<(FindLoopBegin(n10)->id)<<endl;
   return 0;
}