import java.util.*;


public class Solution {
    class node {
        int key;
        int value;
        public node(int key, int value) {
            this.key = key;
            this.value = value;
        }
    }
    List<node> list=new LinkedList<>();
    public int capacity;

    public Solution(int capacity) {
        // write code here
        
        this.capacity = capacity;
    }

    public int get(int key) {
        
        for (node n : list) {
            if (n.key == key) {
                list.remove(n);
                list.add(n);
                return n.value;
            }
        }
        
        return -1;
    }

    public void set(int key, int value) {
        // write code here
        if(list.size()<this.capacity){
            node n=new node(key,value);
            int index=contains(n.key);
            if(index<0){
                list.add(n);
                
            }else{
                list.set(index,n);
                list.remove(n);
                list.add(n);
                
            } 
        }else{
            list.remove(0);
            node n=new node(key,value);
            list.add(n);
        }
    }
    public int contains(int key){
        int i=0;
        for (node n : list) {
            if (n.value == key) {
                return i;
            }
            i++;
        }
        return -1;
    }
}

/**
 * Your Solution object will be instantiated and called as such:
 * Solution solution = new Solution(capacity);
 * int output = solution.get(key);
 * solution.set(key,value);
 */