/*
 public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
*/
import java.util.*;
public class Solution {

    public ListNode EntryNodeOfLoop(ListNode pHead) {
       ListNode temp = pHead;
        Map<ListNode,Integer> m = new HashMap<>();
        while(pHead!=null)
        {
            m.put(pHead,m.getOrDefault(pHead,0)+1);
            if(m.get(pHead)==2)
            {
                return pHead;
            }
            pHead = pHead.next;
        }
        return null;
    }
}