{"problem":{"name":"Dial Up","description":{"content":"Snuke has a sequence of $N$ integers $a=(a_1,a_2,\\cdots,a_N)$ consisting of $0$s and $1$s, and an empty integer sequence $b$. The initial state $a_i=S_i$ is given to you as input. Snuke can do the fol","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc125_a"},"statements":[{"statement_type":"Markdown","content":"Snuke has a sequence of $N$ integers $a=(a_1,a_2,\\cdots,a_N)$ consisting of $0$s and $1$s, and an empty integer sequence $b$. The initial state $a_i=S_i$ is given to you as input.\nSnuke can do the following three operations any number of times in any order.\n\n*   Shift $a$ to the right. In other words, replace $a$ with $(a_N,a_1,a_2,\\cdots,a_{N-1})$.\n    \n*   Shift $a$ to the left. In other words, replace $a$ with $(a_2,a_3,\\cdots,a_N,a_1)$.\n    \n*   Append the current value of $a_1$ at the end of $b$.\n    \n\nYou are also given a sequence of $M$ integers $T=(T_1,T_2,\\cdots,T_M)$. Determine whether it is possible to make $b$ equal to $T$. If it is possible, find the minimum number of operations needed to do so.\n\n## Constraints\n\n*   $1 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq M \\leq 2 \\times 10^5$\n*   $0 \\leq S_i \\leq 1$\n*   $0 \\leq T_i \\leq 1$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $M$\n$S_1$ $S_2$ $\\cdots$ $S_N$\n$T_1$ $T_2$ $\\cdots$ $T_M$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc125_a","tags":[],"sample_group":[["3 4\n0 0 1\n0 1 1 0","6\n\nThe following sequence of six operations will do the job.\n\n*   Append the current value of $a_1$ at the end of $b$, making $b=(0)$.\n    \n*   Shift $a$ to the right, making $a=(1,0,0)$.\n    \n*   Append the current value of $a_1$ at the end of $b$, making $b=(0,1)$.\n    \n*   Append the current value of $a_1$ at the end of $b$, making $b=(0,1,1)$.\n    \n*   Shift $a$ to the right, making $a=(0,1,0)$.\n    \n*   Append the current value of $a_1$ at the end of $b$, making $b=(0,1,1,0)$."],["1 1\n0\n1","\\-1"]],"created_at":"2026-03-03 11:01:14"}}