[Question]
  [
Your input is an array of numbers: a [permutation](https://en.wikipedia.org/wiki/Permutation) of \$\{1, 2 \dots n\}\$ for some integer \$n \geq 2\$.
How many times must you repeat this list before you can "pick out" the numbers \$[1, 2 \dots n]\$ in order?
That is: find the lowest \$t \geq 1\$ so that \$[1, 2 \dots n]\$ is a [subsequence](https://en.wikipedia.org/wiki/Subsequence) of \$\text{repeat}(\text{input}, t)\$.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"): write the shortest program or function that accepts a list of numbers and produces \$t\$.
## Example
For `[6,1,2,3,5,4]`, the answer is `3`:
```
6,1,2,3,5,4    6,1,2,3,5,4    6,1,2,3,5,4
  ^ ^ ^   ^            ^      ^
```
## Test cases
```
[2,1] -> 2
[3,2,1] -> 3
[1,2,3,4] -> 1
[4,1,5,2,3] -> 2
[6,1,2,3,5,4] -> 3
[3,1,2,5,4,7,6] -> 4
[7,1,8,3,5,6,4,2] -> 4
[8,4,3,1,9,6,7,5,2] -> 5
[8,2,10,1,3,4,6,7,5,9] -> 5
[8,6,1,11,10,2,7,9,5,4,3] -> 7
[10,5,1,6,11,9,2,3,4,12,8,7] -> 5
[2,3,8,7,6,9,4,5,11,1,12,13,10] -> 6
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
·ª§>∆ùS‚Äò
```
[Try it online!](https://tio.run/##LY47DsJADEQv5CLe/za0HIAySkmDcgE6RENPlYaOkgsg6FC4R3IRM/YirWTPG2tmD/txPIosr/vme9utp0nm9@eynh/zdXlOmHhbkd4RD9R7apMxPQVsgZiiKuyJGo/meFPYKVOCztDF3ATmQAqmXlWQrCnG0NABIv6Pq2ENZ1bPgVYL1lKACCupWdu3iB2aMkyVRfthBb1jTUEDarvhBw "Jelly ‚Äì Try It Online")
```
·ª§     -- Grade up. Indices that would sort the input
 >∆ù   -- For each pair of adjacent values, is the left larger than the right?
   S  -- Sum the boolean results
    ‚Äò -- Increment by 1
```
[Answer]
# [Python 3](https://docs.python.org/3/), 36 bytes
```
f=lambda x,*p:p==()or(x-1in p)+f(*p)
```
[Try it online!](https://tio.run/##RY5LbsMwDET3OgV3kVKmMCV/A7gXEbpw0QQR4NhCqrTp6V1SjtHlzDwOJ/6myzy5ZTn343D9@Bzggft4jH2vzXzTjwOFCaJ5Oet9NMvPJYwnoKOCMEWE@Z4i9HAdoj59DyOKe0/avH7FMSS9g8Mb7IxREG9hSpo7GDDrnVm8RXoXxCrvcBNOeWLhsMySlC@RsBJrg2tcierJOLkXiw1ssM5mqXzDZpu5mgO72S0L4Tu2G2nOQSUBjyg44efPrPvP5CuRAJajLj9bJzU8uWBNwkhvno9k@XuzFYjXyjrOS4FJ@vghTykyVP8B "Python 3 ‚Äì Try It Online")
The number of repeats needed is equal to the number of pairs `x` and `x+1` such that the `x+1` appears before `x` in the permutation, plus one.
[Answer]
# [Julia 1.0](http://julialang.org/), 30 bytes
```
a->sum(diff(sortperm(a)).<0)+1
```
[Try it online!](https://tio.run/##ZZBBDoIwEEX3nILEDY2jYVpoaaLGexgWJErESDAg0dvXmYJCcPv@m@mf3vp7VeDbleHeFZtD19fRuSrLqGva5@PS1lEhxHYXizW6Y3dtXmEZnSRgLsJVKIMfUvCFaoJIUEHiMU44AYSUo@USDcNEOs6o@X6OKAAD2ofJFBoKMz@nSZDLOCPI85Ziwy97IZ0LVD4mg8qOjv13uB0ii5IU68sMJ5jZyTFxZJff8@cDSmpnFgv5FxVzci1Jqd/NLlLXOBes68B9AA "Julia 1.0 ‚Äì Try It Online")
-2 bytes thanks to @dingledooper.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 6 bytes
```
‚áß¬Ø0<‚àë‚Ä∫
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLih6fCrzA84oiR4oC6IiwiIiwiWzgsNiwxLDExLDEwLDIsNyw5LDUsNCwzXSJd)
Port of ovs's jelly answer.
```
‚áß      # Grade up
 ¬Ø0<   # Cumulative differences less than 0
    ‚àë‚Ä∫ # Sum + 1
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~33~~ ~~31~~ 30 bytes
-1 thanks to [alephalpha](https://codegolf.stackexchange.com/questions/242303/how-many-laps-around-the-permutation/242316?noredirect=1#comment545953_242316)
```
Count[#-##2&@@@#~Subsets~2,1]&
```
[Try it online!](https://tio.run/##LY7BCoMwEETv/kbA0xZM1GgOLYH@QIvH4sGKUg9aqPEk@ut2NvE282bY2bFxn25s3NA2R3897t9lci9xEULF1lqxV8t77ty8K5J1fDyXoXP28Rt86dZbUcd71TbTvkYrKhtFa0qnkBApZSwzkpSzZaMpJHnIUm9hqCDNoAAofa4BFaMSgnsGqOBLAWIoAcXIyU3gvCAlhwrY@ON@GiRHpjk14T2SCmsFp@xL/gJZxkXJdzCC6WSLtuMP "Wolfram Language (Mathematica) ‚Äì Try It Online")
Input `[list]`.
Doesn't work for \$n=1\$, but we're guaranteed \$n\ge 2\$.
---
### [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~37~~ 36 bytes
```
Tr@Boole[Set@a;Set[a,#,a]!=#-1&/@#]&
```
[Try it online!](https://tio.run/##LY5BCoMwEEX33qIEXI3URI1KsUhPULA7cRFEqVAVxJ3o1dM/xk2Y/16YP6NZv91o1qE1ti/sZylf8/zr6qpbS/PAWxsSZJpbIQLp30vR@Pa9DNNai@DZczyq1kzH5m2K5E7eFtE1SAwRxTzGJCnhyEGTM4lz0RkRKCXNIAXITq8BFaMMA//LgVLe5CCKQlCUXDx3nBukZKmA83P5WQ2SwGm2uTuPpEJbypZzxlfAxfxR8h6UoDrcvd3@AQ "Wolfram Language (Mathematica) ‚Äì Try It Online")
The number of repeats is also equal to the number of prefixes `...,x` that don't contain `x-1`.
```
         Set@a;                     clear prefix
                              &/@#  for each:
                           #-1        predecessor
               Set[a,#,a]!=           not in prefix
Tr@Boole[                         ] count
```
[Answer]
# [R](https://www.r-project.org/), 34 bytes
```
function(l)sum(diff(order(l))<0)+1
```
[Try it online!](https://tio.run/##JchBCoAgEEDRfadoOUMGjVoL8TbagFAKluefDFef96vw7FfhlsObSoYLn3ZDTMxQajxrH@g3XEgYtCOcGMwIOfsngFWkdqWVweGju6s/iygf "R ‚Äì Try It Online")
Port of e.g., [Sundar R's answer](https://codegolf.stackexchange.com/a/242308/67312).
# [R](https://www.r-project.org/), ~~77~~ ~~69~~ 67 bytes
```
function(l){while(all(combn(rep(l,T),max(l),is.unsorted)))T=T+1
+T}
```
[Try it online!](https://tio.run/##JclBCsIwFIThfU/h8g19Cmmji1JvkQvUmGDgNZG0RUE8e4x09fPN5OIP47H4Ldo1pEiCz@sRxNEkQjbNt0jZPUnYgOfpXX8Oy2mLS8qruwMwV9OqpjXf4qkbFBpP/R416H8saVZ85o577L5UV9VNA@UH "R ‚Äì Try It Online")
Brute force: `combn(rep(input,t),max(input))` generates all `length(input)` subsequences of \$\text {repeat}(\text {input},t)\$, and check for one that is sorted.
-2 bytes thanks to pajonk.
[Answer]
# [Haskell](https://www.haskell.org/), ~~39~~ 34 bytes
*Thanks [@Unrelated String](https://codegolf.stackexchange.com/users/85334/unrelated-string) for -3 bytes*
*Thanks [@Bubbler](https://codegolf.stackexchange.com/users/78410/bubbler) for another -2 bytes*
```
f[]=1
f(h:t)=sum[1|elem(h-1)t]+f t
```
[Try it online!](https://tio.run/##VZBBDoMgEEX3nsJFF5pOEwdEpIknMSxMKtFUbVPprnenAzYpLOe9D/NhGvb7uCzOmV53mJliutqy299rj59xGddiumBp9dnk1q3DvHW3R5Y/X/NmT6ZngPo/cUhnpJlDHZEaEISnEWvgyIkkyQMlBhKaiEvibUg35FhkWpr9KUVG@i2Jo2YVSarz0yrRvgSizzCyKiyOS5IQFGl8SB3PAmTUROr4N7gnlFKkRbjQp5BqVdp9AQ "Haskell ‚Äì Try It Online")
Port of [@dingledooper](https://codegolf.stackexchange.com/users/88546/dingledooper)'s [Python](https://codegolf.stackexchange.com/a/242320/96039) answer
Answered as part of the current Haskell LYAL event. Tell me if there are any golfs, this is my first time coding in Haskell.
[Answer]
# [Factor](https://factorcode.org/), 42 bytes
```
[ arg-sort differences [ 0 < ] count 1 + ]
```
Port of @SundarR's [Julia answer](https://codegolf.stackexchange.com/a/242308/97916).
## Explanation
Arg-sort the input (i.e. get the indices that sort the input), get their first-order differences, count how many elements are negative, and add one.
```
               ! { 6 1 2 3 5 4 }
arg-sort       ! { 1 2 3 5 4 0 }
differences    ! { 1 1 2 -1 -4 }
[ 0 < ] count  ! 2
1              ! 2 1
+              ! 3
```
[Try it online!](https://tio.run/##VZFNT4QwFEX3/Irr2gyZ8o0at8aNG@NqMosGHyMRC7adxNH42/G9gg5uSDnnvo9Cqxs/2Onp8f7h7goHMmR1331q3w3G4ZWsoR5v2r@ER@w8G@e7xmG05P1ptJ3xcPR@JNOQO59i@vBWO1xH0RcSKHzjAptbJPyarkHKQDFIkf0ixShjmAe8KiyWZH7OpqGfYIElRxaRsShZVCFfsEzWqmIgdTWrMkxaZB4kL7hlK0vNvv7vZROlJJSwrsPwv1VLudKWmZKczJivpxKuLNeNhFdh65p9HlpKTKXSYAkW0bSDtoeNG6zHc9e2ZOevvcMWN9ijGY78FxQusZ@42uhx7E@IHZqetJ1@AA "Factor ‚Äì Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~11~~ ~~8~~ 7 bytes
```
&Sd0<sQ
```
[Try it online!](https://tio.run/##y00syfn/Xy04xcCmOPD//2hDAx1THUMdMx1DQx1LHSMdYx0THUMjHQsd81gA "MATL ‚Äì Try It Online")
Straight port of my Julia answer (using the second output of `sort` in place of `sortperm` - thanks to @Giuseppe for that idea, saving me 3 bytes).
Another -1 byte thanks to @LuisMendo (so rusty with MATL I forgot `&` even existed!)
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 24 bytes
```
@(a)nnz(tril(a==a'+1))+1
```
[Try it online!](https://tio.run/##PY7LCoNADEX3/YruOoNBzKjzWAj9j@JiKBUKxUIRF/356Y3R7pJzQu5935e8Psp0Huq6LleT7Tx/zfJ5vkwehnyp2NqKy2Rujni0Jwwt/UfG2FKnS0dMvQBdPantD99uACsF8ooCUNxuPLBTGDHKbQIM8vHAiG3AEbibdBjJYhbtINIWstcA62G9@KR1iR1Sg3ohURrBdnLK8gtRqNCMtvwA "Octave ‚Äì Try It Online")
Port of [@dingledooper's Python 3 answer](https://codegolf.stackexchange.com/a/242320).
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), ~~49~~38 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{0=‚åà/‚çµ:1‚ãÑ~1‚àä‚ç∫:1+‚çµ‚àá‚çµ‚ãÑ(‚çµ-1)‚àá‚ç®¬Ø1+‚ç∫‚Üì‚ç®‚ç∫‚ç≥1}‚ç®
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=e9Q31dNf4VHbBAUDAA&c=qzawfdTTof@od6uV4aPuljrDRx1dj3p3WRlqA4UedbSDyO4WDSCla6gJ5q84tB4kuetR22QgB8To3WxYC2QCAA&f=VU@7DcJADO0zhUsiuYjvf/sQPlKkFBcYAYkCiQUo6JiDUTIJz3c0kXWy/T72eRnLUmi9PWlnSHraWWpZkC05VI6EvHaoAzXcg@mW6uVqtixs2LPjyAHCiD6xBRKAGSAJWVUZSARutgMS7DKAt9A1Ra6uAExEOQM01x126wXnoQqqy5DpCDHYHzFB26S/AuVUJzoQy/CZoe/KPLX79az/0QiPiHihCtb7@/D9tJXr40XlNF@mPR3P15HkBw&i=AwA&r=tryapl&l=apl-dyalog&m=dfn&n=f)
A dfn submission which uses recursion (yuck) to keep track of things.
Instead of looking for increasing numbers, we decrement the sequence and always look for a `1`: this means that, as we recurse, we don't need to keep track of the number we are searching for.
`‚ç∫` contains the tail of the sequence where we can still look for 1s, and `‚çµ` contains a copy of the original sequence, but decremented by the amount of times we already found the next digit.
Then, we just look for the next number in the sequence tail.
* If it's there, chop the sequence tail and call the function recursively, after decrementing the original sequence again and the new tail.
* If it's not there, use `‚çµ` to reset the sequence tail, and add a `1` to the recursive result because we needed one extra repetition.
Recursion stops when the decremented copy of the original sequence has 0 as its largest element.
---
@Razetime also shared a ‚Äúboring Jelly port‚Äù in the comments for 8 bytes:
```
1+1‚ä•2>/‚çã
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~9~~ 8 bytes
```
{‚äáƒä-1}·∂ú<
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/v/pRV/uRLl3D2ofb5tj8/x9toWOmY6hjCEQGOkY65jqWOqY6JjrGsf8jAA)
### Explanation
Saved 1 byte by porting everybody else's approach.
```
{‚äáƒä-1}·∂ú<
{    }·∂ú   Count how many ways there are to satisfy this predicate:
 ‚äá          A subsequence of the input
  ƒä         Of length 2
   -        Has a difference (first element minus second element)
    1       Equal to 1 (first element is 1 + second element)
       <  The output is the next integer larger than that result
```
---
Old solution that implements the spec directly:
```
;.j‚Çé‚äá~o?‚àß
;           Pair the input with
 .          Some as-yet unknown value which will be the output
  j‚Çé        Repeat the former a number of times equal to the latter (trying 0 first,
            then 1, then 2, etc., until the rest of the predicate succeeds)
    ‚äá       Some subsequence of the result
     ~o     Is a sorted version of
       ?    The input
        ‚àß   Output whatever we calculated earlier as .
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/31ov61FT36Ou9rp8@0cdy///jzbTMdQx0jHWMdUxif0fAQA "Brachylog ‚Äì Try It Online")
[Answer]
## Python3, 109 bytes:
```
from itertools import*
f=lambda x,c=1:c if any(sorted(x)==[*i]for i in combinations(x*c,len(x)))else f(x,c+1)
```
[Try it online!](https://tio.run/##RZFRboMwEES/61Os8hNI3SgGAiQSPUIvQKPKEKNaMjbCVpWcnu46of3cmeedkXe6h29n83qal2WY3Qg6qDk4ZzzocXJz2LGhMXLsrhJuvG/EuQc9gLT3xKOrrsktbZp2py@Dm0GDttC7sdNWBu2sT267nhtlkUpTZbyCIcE1ryJdfLPZbFibcXGBt3fIWJvzdchZK3DIeRFHwdqCC34kaYVL/iCOTyan9yShwCteRrFgbYViHbkSjWyVaxyIP6Fc0eZoHMnAEgd0MPzpnf49ShWCgAytUwx7VKqw8gFnQQztjfW5yDC9WheQVlM79AuCBe3DQKxyiFDJ6FceXw/SB/b3rYM2eJrkw1nFwe/9ZHRItp92m6Zn9iI5dNDAKKcEX@0NnVGaL/UjDQe90pSAPOLe45nxGBKv1y2/)
Brute force solution, extremely slow.
## Python3, 115 bytes:
```
v=lambda o,n:not o or(o[0]in n and v(o[1:],n[n.index(o[0])+1:])) 
f=lambda x,c=1:c if v(sorted(x),x*c)else f(x,c+1)
```
[Try it online!](https://tio.run/##RZHBboMwEETP9VescgluthEGEhIkesyxP0BR5QSjWiI2wihKvz7ddYp63Jm3Myt7/Jm/vcsP4/R43OpBX8@dBo@ucn4GD35KfJO21oED7Tq40aiqFl3jttZ15h5tuSFNShD9knDHS62qC9ieVoKfZtMld4n314s0QzDQJ0RslHyEerVaiSZD1cLbO2SiyXEZctEoGnIs4qhEU6DCHUsLvMcnsftjct5niQQscR/FQjQliYfI7cnIFvlAA/NHkktOjsaODToiJYfK/7zjv8etSjGQkXWMZc@TSjo5pVkxw7nxfFQZtZdLAGsHvo78gmHFeVRIp6QR2gt@FXsd6eVAh1n0fgIL9A29HWYzJR/eGYSwDeNg52T96dZSVuJFI5yhhqseE9rakmcmPXyZmx4Q7EJzA/GEh2CoIDlVdZ9oKev6jNBQyIlyWjFO1hE@mzAHGBnu1vLxCw)
Much faster version.
[Answer]
# JavaScript (ES6), 45 bytes
```
f=(a,k=0)=>a.some(n=>!a[k+=k+1==n])||1+f(a,k)
```
[Try it online!](https://tio.run/##fZDNDoIwEITvPoXeaFiRLT@FQ30R46FBNApSI8aT7467WDUR8Nr5ZjqzJ3M3bXE9Xm7Lxu7Krttrz0ClQ6HXJmjtufQavV6YTeXryketm614PNDfMyW6wjatrcugtgeP3jYScCvEfLWay9mvFsFXjQYqkhpB7HQc6DEgJMxM5qfwykg@KdFIB2aIAAWpo@IBpYjK@qSUSDnJZaRyYk6c4naOTEZI2h4SShMdnP@BeQoiOySxeV/4PVwNTxcSgGziKv0ZASUtUJNfMJTxDcgQsxv5R@pIc0LnSrsn "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 8 bytes
```
1+/<':<:
```
[Try it online!](https://ngn.codeberg.page/k#eJxFjs1ugzAQhO9+Ch8qtVVNYG2DAUd9ERQpKCU/SgIpEDVR1T57Z01Qb7vfzO7MtqS3ePlcLkshxvL7qbr/9uVWSnnz6+7oX9bb+nDyN3/3/evqR4yVluT1CoORPBoeCaOR1hMvVpJMGUy2TE5qCt1MdwywSiczbxk5oDx4MmA9wRwjewtAxx99OmHEJuAIfCjFrHAWEcsaQhFCjHehYoKN2MEfQ11JGqluOmaScyOolq3EvxCFConPVkLEYj+Ol6GM40330ey603YxjPXm2Nw2+7rdNYtNd44/r80wHrp2iLXVJjHxvvuKznV7j071ZYjqvru2H9G4b6JL05+vY81mUWlFKxm9Sy0qo+bFiIqwGGXDSqKyilTKaDZnanKkD4/he0YAyqksQCsqB5gHXwZBzzjHwv4C2PHnIKQsoEQCBeEPrfjXOJWIDRpSEcKmSg6VE+zEHv4b6ivSSHfzA2Y5t4Nu2Uz8D4GokgRT9gcxk5WY)
Essentially a port of @ovs' [Jelly answer](https://codegolf.stackexchange.com/a/242305/98547).
* `<:` [grade-up](https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Manual.md#asc) the input (generates a permutation vector which would sort argument into ascending order)
* `<':` check if each value is less than its predecessor
* `1+/` take the sum, seeded with 1
[Answer]
# [Desmos](https://desmos.com/calculator), 55 bytes
```
l=sort([1...L.length],L)
f(L)=\total(\{l[2...]<l,0\})+1
```
[Try It On Desmos!](https://www.desmos.com/calculator/xxtr47njj1)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/vwhjb4g0sa)
\$f(L)\$ takes in a list \$L\$ and returns the lowest value of \$t\$ as specified in the challenge.
The code basically just does the "grade up" trick that many of the other answers were doing.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 10 bytes
```
Ôº©Œ£Ôº•Œ∏‚Ä∫Œ∫‚åïŒ∏‚äïŒπ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8M3sUCjUEfBvSg1sSS1SCNbR8EtMy8FJOSZl1yUmpuaV5KaopGpCQHW//9HRxvpGOtY6JjrmOlY6pjomOoYGuoAoZGOobGOoUFs7H/dshwA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Based on @dingledooper's observation that the number of repeats is `1` plus the number of times `x+1` appears before `x`, although because `Find` returns `-1` when the value is not found, the formula believes `n+1` appears before `n`, thus automatically adding the extra `1` to the result.
```
   Œ∏        Input array
  Ôº•         Map over values
     Œ∫      Current index
    ‚Ä∫       Is greater than
      ‚åï     Index of
         Œπ  Current value
        ‚äï   Incremented
       Œ∏    In input array
 Œ£          Take the sum
Ôº©           Cast to string
            Implicitly print
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
>kƒÅ<‚ÄπO
```
The same approach as [*@dingledooper*'s uses in his Python answer](https://codegolf.stackexchange.com/a/242320/52210).
[Try it online](https://tio.run/##yy9OTMpM/f/fLvtIo82jhp3@//9Hm@kY6hjpGOuY6pjEAgA) or [verify all test cases](https://tio.run/##LY47DgIxDESvstraxTr/SIht6DlAlAIkCkRBgYS0HTQcgNvQc5K9SBg7VPa8sWZ8vR2O51O7L/M4rK/3MM7Lrm0v3@dmfXz2jVophrhSsdQnY1py2BwxeVHYA3Xu1bGqsFOkAB2hk7oBzIAkTLnKIFFSlKFhAkT8H2fFEs4sngHNGiylAB5WEDP3t4gNmiJMkUn6YTm5Y0lBA2qnWn8).
**Explanation:**
```
>       # Increase each value in the (implicit) input-list by 1
 k      # Get the index of these values in the (implicit) input-list
        # (or -1 for the max+1 that isn't found)
  ƒÅ     # Push a list in the range [1,length] (without popping the list)
   <    # Decrease each by 1 to make the range [0,length)
    ‚Äπ   # Do a smaller than check for the values of the two lists
     O  # Sum the amount of truthy values
        # (which is output implicitly as result)
```
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$ 15 \log\_{256}(96) \approx \$ 12.35 bytes
```
e1+z0AhEDLRz.<S
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhbrUw21qwwcM1xdfIKq9GyCIaJQyQVro810DHWMdIx1THVMYiGCAA)
Port of Kevin Cruijssen's 05AB1E answer.
#### Explanation
```
e1+z0AhEDLRz.<S  # Implicit input
e      E         # For each number in the input:
 1+              #  Increment it
     Ah          #  And get the index
   z0            #  in the input (-1 if not found)
        DLR      # Duplicate and push [0..length]
           z.<   # Do a less than check
              S  # Sum the truthy values
                 # Implicit output
```
[Answer]
# [Uiua](https://uiua.org), 10 bytes [SBCS](https://www.uiua.org/pad?src=0_7_1__IyBTaW5nbGUtYnl0ZSBjaGFyYWN0ZXIgZW5jb2RpbmcgZm9yIFVpdWEgMC44LjAKIyBXcml0dGVuIGhhc3RpbHkgYnkgVG9ieSBCdXNpY2stV2FybmVyLCBAVGJ3IG9uIFN0YWNrIEV4Y2hhbmdlCiMgMjcgRGVjZW1iZXIgMjAyMwojIEFQTCdzICLijbUiIGlzIHVzZWQgYXMgYSBwbGFjZWhvbGRlci4KCkNPTlRST0wg4oaQICJcMOKNteKNteKNteKNteKNteKNteKNteKNteKNtVxu4o214o21XHLijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbUiClBSSU5UQUJMRSDihpAgIiAhXCIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0-P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX7ijbUiClVJVUEg4oaQICLiiJjCrMKxwq_ijLXiiJril4vijIrijIjigYXiiaDiiaTiiaXDl8O34pe_4oG_4oKZ4oan4oal4oig4oSC4qe74paz4oeh4oqi4oeM4pmtwqTii6_ijYnijY_ijZbiipriipviip3ilqHii5XiiY3iip_iioLiio_iiqHihq_imIfihpnihpjihrvil6vilr3ijJXiiIriipfiiKfiiLXiiaHiip7iiqDijaXiipXiipziipDii4XiipniiKnCsOKMheKNnOKKg-KqvuKKk-KLlOKNouKsmuKNo-KNpOKGrOKGq-Kags63z4DPhOKInuK4ruKGkOKVreKUgOKVt-KVr-KfpuKfp-KMnOKMn-KVk-KVn-KVnCIKQVNDSUkg4oaQIOKKgiBDT05UUk9MIFBSSU5UQUJMRQpTQkNTIOKGkCDiioIgQVNDSUkgVUlVQQoKRW5jb2RlIOKGkCDiipc6U0JDUwpEZWNvZGUg4oaQIOKKjzpTQkNTCgpQYXRoVUEg4oaQICJ0ZXN0MS51YSIKUGF0aFNCQ1Mg4oaQICJ0ZXN0Mi5zYmNzIgoKRW5jb2RlVUEg4oaQICZmd2EgUGF0aFNCQ1MgRW5jb2RlICZmcmFzCkRlY29kZVNCQ1Mg4oaQICZmd2EgUGF0aFVBIERlY29kZSAmZnJhYgoKIyBFeGFtcGxlczoKIwojIFdyaXRlIHRvIC51YSBmaWxlOgojICAgICAmZndhIFBhdGhVQSAi4oqP4o2PLuKKneKWveKJoOKHoeKnuyziipdAQi4iCiMgRW5jb2RlIHRvIGEgLnNiY3MgZmlsZToKIyAgICAgRW5jb2RlVUEgUGF0aFVBCiMgRGVjb2RlIGEgLnNiY3MgZmlsZToKIyAgICAgRGVjb2RlU0JDUyBQYXRoU0JDUwo=)
```
+1/+/<‚çâ‚ó´2‚çè
```
[Try it!](https://uiua.org/pad?src=0_7_1__ZiDihpAgKzEvKy884o2J4perMuKNjwoKZiBbMiAxXQpmIFszIDIgMV0KZiBbMSAyIDMgNF0KZiBbNCAxIDUgMiAzXQpmIFs2IDEgMiAzIDUgNF0KZiBbMyAxIDIgNSA0IDcgNl0K)
[Answer]
# [Scala 3](https://www.scala-lang.org/), 70 bytes
Golfed version. [Attempt This Online!](https://ato.pxeger.com/run?1=hZJNToNAFMcTlz3FS1czkVIGKNBGmujCpAtXxrhommZsS8XQgcBUraYn8AhuutGNJ6qncZgH6gIrC5iQ3__jPXh9L2Y84c7HuN0R6QPPRXuyP05v7hYzCRc8FvDcagHc8wSiAZDTPOeb8UjISThUdwrh21pGnWB_PjWf4uw6lrcjMV88mkWay7MNmZpTRs0Vz8qTTc0iieexWBJ1nKVrIUkWDjPC6ElGLEqPGbp9Hr0AzBcRrFQBwvNlMQBMvpS5kk_oAK5ELCFU7UBdmXorE0EiLEhsAxilFLpdsBsBx4BfjNPIMM0o0q0w1oi5yseAHsIHQz1Nomfvx7Y53anhkjTAN8CreLeR9zUf1OaeVtkHJYFmMKivJT4OUql6f6nK1Vla5miLb2X_PyWugDE0sLWuX89Yb89v_hyW5hiaYGW7bsBsPbt_MB_pAJep9S5aMmxVjlVuw6pcPOWybW3xn9zt8PkF)
```
_.zipWithIndex.sortBy(_._1).map(_._2).sliding(2).count(p=>p(1)<p(0))+1
```
Ungolfed version.
```
def f(a: Array[Int]): Int = {
    val sortedIndices = a.zipWithIndex.sortBy(_._1).map(_._2)
    sortedIndices.sliding(2).count(pair => pair(1) < pair(0)) + 1
}
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 28 bytes
```
\d+
$*
\b1(1*)\b(?=.*\b\1\b)
```
[Try it online!](https://tio.run/##LY47DgIxDER7nwOkbLDQOv8UiJJLpIAIChoKtPcP4yyN5XnjzOT72t6fxzia232054kOlloXI3Zp3VwvZ9t6k9aXMRwLedYpmJ4DBRaOulPinUVQP3dsnDlRhirTSSCOCqZeVOisr0GQuQIh8g8roEaKqOPA6gz0BBlhJLXq/g0Wh4ZMKop2wgh6JZqAbNStPw "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Explanation: Uses @dingledooper's observation again.
```
\d+
$*
```
Convert to unary.
```
\b1(1*)\b(?=.*\b\1\b)
```
Count the matches of `1+$.1` that are followed by `$.1`. When this is positive, the word boundary anchors simply ensure that `$.1` is exactly matched, but conveniently when `$.1` is `0` we get an extra "false" match which automatically increments the final result for us.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~70~~ 57 bytes
```
i;t;f(a,n)int*a;{for(i=t=n;t;)a[i%n]+t+~n?i++:t--;a=i/n;}
```
[Try it online!](https://tio.run/##XZRtj5swDMff36eIKlWCEnSEZ46xezHtU7TVhCi9RXdLTwVp1Sr20dc5cWhjEMXEv78dx0npwreuu91kPdZHr@XKl2rctPX1eDp7shkbBcBvt3Kt9sEY/FWvMghexjCs20Y@q3q6gZ79aqXyfHZ9YnBpx9gPo9juWcOuMRdTfXfG6Ew4dSfoFuBOeOqAFEHKBc80dFCGKOcYlZG4fJ5HQ0C84LmDC8QF4NLE5iCJHUGJghLcOkcFgkJX4EiqWQJLiUADhVtV5ahENMt0oUJobQyqylTlrkfYhoEgA2muxRU2hIsY6ixccTx3N9EE1BXIMjOBVguoOppqsiE/FMYM8k9/Onomjf9sRxsccubQmNKY0oTShNKU0pTSjNKM0pzSnNKC0oLSktKS0orSilIRLdoRLfiyXYt@iUXDYPzYgo3ZgwG3wFCO/wg0CZoUTYYmR1OgKdFU3B4sa20eETvb3V8@@27sD/MhYZAedPiSmjszd2GeuQ3tTmoYWfezPW/g2Xfv/RkzrHaX7/HuUn2DX7bizB0nKxsNnwzm6dmlOvQXCItq@/pl7tJc16NPd0/NgsCofZMMvyWP3kE67J/R7GsXM2UpnPAlfhRlC4JilJnLv2v09XkG0dFbrYf1ARYoX/UqX1ZbMONW7n064QDJYM/hc0n9PfjvvV@WMk@xZ@FXtj6w9bBTkH7g9173TTPMU01P0@1fd/xo34Zb@Ps/ "C (gcc) ‚Äì Try It Online")
*Saved a whopping 13 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203/att)!!!*
Inputs a pointer to an array of numbers that are a permutation of \$\{1, 2 \dots n\}\$ and \$n\$ (because pointers in C carry no length info).  
Returns how many times this array must be repeated before you can *pick out* the numbers \$\{1, 2 \dots n\}\$ in order.
[Answer]
# [PHP](https://php.net), ~~81~~ ~~74~~ 67 bytes
```
array_reduce($a,function($c,$x){return[$x,$c[1]+($x<$c[0])];})[1]+1
```
Implementation of algorithm from ovs' answer: count all pairs where right < left, then add 1.
Since array\_reduce takes only one "carry" param, but we want each iteration to know both the running total and the previous value, we make 'carry' be an array with both elements in, which is a few bytes shorter than making a global, but makes a warning the first time we access the (uninitialized) array.
Reduced from first submission by moving all calculation into the return.
Reduced further since it apparently doesn't need to be a program, just a code snippet that takes an array and outputs a value, so all the boilerplate can go away into a header/footer.
[Try it online!](https://tio.run/##NZDNqoMwFIT3PkUWWSg9C@O/2EsfREIJaYrdqKQVvJQ@u50TbTaZ882QOWQe5u18mYc5ksZ78/8Uf6KPRJ@R0oQ7p59SUDkVQRekqOQ5TBXtXnm4eZgxUU1VIDVIExIVaBZYA8XJFqzm1w6KvhQYVYfRHgbXKMVuBt6Ggn0BoBJmxXa7r0kqQ2MdbAYN7wKz4KTil9CD@hQJ3UX3yTtjBxH/fsE8hTSJeEfODpPYAr16d1usQ4buy2hfj2mMpSW5Jm/vXosfe7mStL3Sp1iuZ6hUJ7r7JEzU1n02nC8)
[Answer]
# [Perl 5](https://www.perl.org/), 58 bytes
```
sub{$_="@_;"x@_;my$i;1while++$i&&s/.*?\b$i\b//;1+@_-y/;//}
```
[Try it online!](https://tio.run/##bZDNbsIwEITvPMUqcgkU0@D8B8sl90rl0hugSLQOtQokCqCCEM8e1g6VgujFseeb3Z1NKat1UJNc1LvD8kwyYaUZt454bE5Ecfb7rdZyMCCq2905L8@T@ZKo@dJxOBuk2fDkcMe51LyTF1WvMwOAmUvZAsQruPhY0Ebz6J/qtVSGqkd9o7OW7lNGA80e@oS0qQluVd7dDM2Q0IiGhvotGiGNTWWIDveBx6jqDgnySE83juDOgTuM0IKRb6bkH5OOyJh2uuhJTKBmkai9@ggB02Y90vwGylxMGD201DDWO6HR11VMT8AsGHdk3GHjxhP6Z/PZnHpEUSL7IiUZv0lkJbok76VE9RuprNR2n1tPw3AHII@l/NzLrzEQiWxV7PG2wpvalge8Y9l8a1GkQqA@Abv4sWEM9vv0A6ZvNu9c6is "Perl 5 ‚Äì Try It Online")
]