#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) {
	if(!head) {
		return NULL;
	}
    Node *slowptr = head,*fastptr = head;
    do {
        fastptr = fastptr->next;
        if(fastptr == NULL) {return NULL;}
        fastptr = fastptr->next;
        slowptr = slowptr->next;
    }while(slowptr && fastptr && slowptr != fastptr);
    if(slowptr && fastptr && slowptr == fastptr) {
        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;
}