[Question]
  [
The totient function \$\phi(n)\$, also called Euler's totient function, is defined as the number of positive integers \$\le n\$ that are relatively prime to (i.e., do not contain any factor in common with) \$n\$, where \$1\$ is counted as being relatively prime to all numbers. (from [WolframMathworld](http://mathworld.wolfram.com/TotientFunction.html))
## Challenge
Given an integer \$N > 1\$, output the lowest integer \$M > N\$, where \$\phi(N) = \phi(M)\$. If \$M\$ does not exist, output a non-ambiguous non-positive-integer value to indicate that M does not exist (e.g. 0, -1, some string).
Note that \$\phi(n) \geq \sqrt n\$ for all \$n > 6\$
## Examples
```
Where M exists
 15 -> 16  (8)
 61 -> 77  (60)
 465 -> 482 (240)
 945 -> 962 (432) 
No M exists
 12  (4)
 42 (12)
 62 (30)
```
Standard loopholes apply, shortest answer in bytes wins.
[Related](https://codegolf.stackexchange.com/q/83533/90146)
  
[Answer]
# JavaScript (ES6), ~~83 ... 76~~ 74 bytes
Returns `true` if \$M\$ does not exist.
Derived from [this answer](https://codegolf.stackexchange.com/a/83636/58563) by xnor.
```
f=(n,q,P=(n,d=n)=>p=--d&&P(n,d)+1-P(n%d?1:d))=>P(n)^q?p>q*q||f(n+1,q||p):n
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zVYjT6dQJwBEpdjmadraFdjq6qaoqQWABDS1DXWBDNUUe0OrFE2gJJCjGVdoX2BXqFVYU5OmkadtqANkFGha5f1Pzs8rzs9J1cvJT9dQj/ZVSK3ILC4pjlXXtOZClkrTMDTV1EQTMjPEEDIxw1RmaQISQxFUj8mLzstXwGedEabZmEJmQKH/AA "JavaScript (Node.js) – Try It Online")
## How?
### Computing \$\phi(n)\$
This is based on the formula:
$$\sum\_{d|n}\phi(d)=n$$
which implies:
$$\phi(n)=n-\sum\_{d|n,d<n}\phi(d)$$
But in the JS implementation, we actually compute:
$$\begin{align}P(n)&=\sum\_{d=1}^{n-1}1-\delta\_{d|n}P(d)\\
&=n-1-\sum\_{d|n,d<n}P(d)\end{align}$$
It leads to the same results, except \$P(1)=0\$ instead of \$\phi(1)=1\$. This is fine because we don't need to support \$n=1\$, as per the challenge rules. And this allows us to do the following recursive call:
```
P(n % d ? 1 : d)
```
which evaluates to \$0\$ if \$d\$ is not a divisor of \$n\$.
### Wrapper code
At each iteration, we compute \$p=P(n)\$. The result of the first iteration is saved into \$q\$. We then increment \$n\$ until \$p=q\$ (success) or \$p>q^2\$ (failure).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
r²ÆṪẹḢ$+⁸Ḣ
```
A monadic Link accepting a positive integer which yields a non-negative integer (`0` if no \$M\$ exists).
**[Try it online!](https://tio.run/##y0rNyan8/7/o0KbDbQ93rnq4a@fDHYtUtB817gDS////NzMEAA "Jelly – Try It Online")**
### How?
```
r²ÆṪẹḢ$+⁸Ḣ - Link: integer, n
 ²         - (n) squared
r          - (n) inclusive range (n²)
  ÆṪ       - Euler totient (vectorises)
      $    - last two links as a monad:
     Ḣ     -   head    - i.e. yield totient(n)
                           and leave [totient(n+1),...,totient(n²)]
    ẹ      -   indices of (i.e. a list of offsets to higher Ms)
        ⁸  - chain's left argument (n)
       +   - add (vectorises) (i.e. a list of higher Ms)
         Ḣ - head (note head-ing an empty list yields zero)
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~57~~ 52 bytes
*-5 bytes using the `.&` operator thanks to Jo King*
```
{first *.&($!={grep 1,($_ Xgcd^$_)})==.$!,$_^..$_²}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/Oi2zqLhEQUtPTUNF0bY6vSi1QMFQR0MlXiEiPTklTiVes1bT1lZPRVFHJT5OT08l/tCm2v/FiZUKaUA1mgpp@UUKhqY6CmaGOgomZkCGpQmQMDQC8oDYzOg/AA "Perl 6 – Try It Online")
Returns `Nil` if no solution was found.
### Explanation
```
{                                                 }  # Anonymous block
                       $_ Xgcd^$_     # gcds of m and 0..m-1
               grep 1,                # Filter 1s
              {                   }   # Totient function
          ($!=                     )  # Assign to $!
 first                                   ,$_^..$_²  # First item of n+1..n² where
       *.&                          ==.$!           # ϕ(m) == ϕ(n)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ 12 bytes
```
r²ÆṪ=€Ḣ$T+⁸Ḣ
```
[Try it online!](https://tio.run/##y0rNyan8/7/o0KbDbQ93rrJ91LTm4Y5FKiHajxp3ABn/rR81zFHQtVN41DDX@nA71@F2oILI//8tdAyNdAxNdUyMdMwMdcyMAA "Jelly – Try It Online")
A monadic link taking an integer and returning the next integer with shared totient or zero. 
## Explanation
### Main link (takes integer argument z)
```
r²           | Range from z to z ** 2 inclusive
  ÆṪ         | Totient function of each
       $     | Following as a monad
    =€Ḣ      | - Check whether each equal to the first, popping the first before doing so
        T    | Truthy indices
         +⁸  | Plus z
           Ḣ | - Head (returns 0 if the previous link yielded an empty list)
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~11~~ ~~10~~ ~~9~~ 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
L+.Δ‚ÕË
```
-1 byte with help from *@ExpiredData*.  
-2 bytes thanks to *@Grimmy*.
Outputs `-1` if no \$m\$ exists.
[Try it online](https://tio.run/##yy9OTMpM/f/fR1vv3JRHDbMOTz3c/f@/mSEA) or [verify all test cases](https://tio.run/##AUIAvf9vc2FiaWX/dnk/IiDihpIgIj95wqnDkP9MKy7OlMKu4oCaw5XDi/99LP9bMTUsNjEsNDU2LDk0NSwxMiw0Miw2Ml0).
**Explanation:**
```
L        # Push a list in the range [1, (implicit) input-integer n]
 +       # Add the (implicit) input-integer n to each to make the range [n+1, 2n]
  .Δ     # Get the first value of this list which is truthy for
         # (or results in -1 if none are truthy):
    ‚    #  Pair the current value with the (implicit) input-integer n
     Õ   #  Get the Euler's totient of both
      Ë  #  Check whether both are equal to each other
         # (after which the result is output implicitly)
```
Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the [Mathematica implementation on the oeis sequence A066659](https://oeis.org/A066659) we can see it also uses the range \$[n+1, 2n+1)\$ to check in.
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 11 bytes
```
:sUt¦ṇ=∆:+¿
```
[Try it online!](https://tio.run/##S0/MTPz/36o4tOTQsoc7220fdbRZaR/a//8/AA "Gaia – Try It Online")
```
:s		| push n,n^2
  U		| push range [n, n + 1, ..., n^2]
   t¦		| calculate [phi(n),phi(n+1), ..., phi(n^2)]
     ṇ		| push [phi(n+1), phi(n+2), ..., phi(n^2)], phi(n)
      =∆	| find 1-based index of first in the list equal to phi(n), returning 0 if none
	:	| dup the index
	 +¿	| if the index is falsey, do nothing (leaving 0 on the stack)
		| otherwise add (implicitly) n
		| and implicitly print top of stack
```
[Answer]
# [Python 2](https://docs.python.org/2/), 115 bytes
```
lambda N:next((j for j in range(N+1,max(6,t(N)**2))if t(j)==t(N)),0)
t=lambda n:sum(k/n*k%n>n-2for k in range(n*n))
```
[Try it online!](https://tio.run/##jc7BCoJAEIDhc/sUcxFnbKVcVEiwR9gXqA4buqXmFLpCPr1lCNGtyxyGn2/mMbrrndVk8@N0M@25MKAzLp8OsQZ776CGiqEzfClRryPZmiem0qGmIFBElQWHNeX5vCG5JeHyheGsH1psNhw0Hu85VLPWfDUOmGh6dBU78F03uOvoi7nRc3OIEplGMk4TuYuTUyZWS@kVEO7hPdEryPdQS/s@/fmIhFgia259@cspGas/mekF "Python 2 – Try It Online")
Returns `0` for falsey. The totient function `t` is based on [Dennis's answer](https://codegolf.stackexchange.com/a/145316/69880) to a previous question.
Times out on TIO for `N=62`.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~70~~ 68 bytes
```
->n{(n+1..n*n).find{|m|g=->g{(1..g).sum{|h|1/h.gcd(g)}};g[m]==g[n]}}
```
[Try it online!](https://tio.run/##bcrBCsIgHIDx@55it2mpoTghwr2IeKiG/3VQpCUY6rPbHqDv@ON7p8e3O93pEgoKZ85YOAXM3CuspfoKmi5Q0MGA2Z58qVvll43Bc0WAW7uB8VZrMMG21g2fieJEqplc5WyZv8dSc42jycSZbG0bYvrs40SPpsFwQaQgSvw7@w8 "Ruby – Try It Online")
Returns `nil` if not found.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~160~~ 121 bytes
Saved 39 bytes thanks to @JoKing!
Returns `None` if no \$M\$ exists:
```
import math
t=lambda n:sum(math.gcd(i,n)<2for i in range(n))
def s(x):
 n=x
 while n<x*x:
  n+=1
  if t(n)==t(x):return n
```
[Try it online!](https://tio.run/##PU7LCoMwELznK5aektYKsVaomP5LWqMGzCox0hTx29P10oV9DTPDzN8wTHhLybp58gGcDgMLatTu1WrAelkdP7C8f7fcZiiaops8WLAIXmNvOArBWtPBwqOoGaCKDD6DHQ1gE8@RIMCLkrRsB4HoSoWD6k1YPQKmvx@X9wwqmUFZ0fEoaciCPuqqOLypZm8x8NO2w/UJ237KSU35KBoFsEKI9AM "Python 3 – Try It Online")
If throwing an exception is allowed when no \$M\$ exists:
# [Python 3](https://docs.python.org/3/), ~~145~~ 114 bytes
Saved 31 bytes thanks to @JoKing!
```
lambda n:[t(i+1)for i in range(n,n*n)].index(t(n))-~n
import math
t=lambda n:sum(math.gcd(i,n)<2for i in range(n))
```
[Try it online!](https://tio.run/##XYxBC4JQEITv/opFEHbrFWjlQapb/Ynq8MqXLuQq721Ql/66mQcPDQwDw8zXvbVuZdWH3bl/2OZaWpDipMjzlO6tBwYW8FYqh2JkJnRZspTuhYpCtPhIxE3XeoXGah3pbmKEZ4O/blndSmQjtM3@eUT9VGG6MZCnBtLMwHpwnlERwSD17wI6z6IYJwEWe0hCnAxICMhENI7c6@Y6hcMY3Mrf42gfwcUJU/8F "Python 3 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 97 bytes
```
lambda x,n=1:[n>x*x,x+n][t(x+n)==t(x)]or s(x,n+1)
t=lambda n:sum(k//n*k%n>n-2for k in range(n*n))
```
[Try it online!](https://tio.run/##VcvRCoIwFAbge59iEMGmlsxMUJgvYl5YWQ3dmWwT5tOvc1FhBw4/H@c/8@peGk5BqlkbR@xqI9yjHZwZbouxUsMklXS0wmGRFZcw9ep674lPQfC6hcbHPvUJdK2jGEwITNZpQyzFTsJZ5MTnB2q7KDpmGcTjHho45A/sjUQCMT08BwoxMBZmI8FRS/mZseiLkm9QlNtTVWzFc8Tu1/xTiQpv "Python 3 – Try It Online")
Totient function taken from [Chas Brown's answer](https://codegolf.stackexchange.com/a/196653/76162), originally from [Dennis](https://codegolf.stackexchange.com/a/145316/69880).Returns `True` for cases where `M` doesn't exist, though if that doesn't satisfy you, a far less efficient version that returns `False` is only [two bytes longer](https://tio.run/##VYvhCoIwFIX/@xSDCDa1ZGaC0noR88dKq6G7k23CfPq1oCIvHA7fOfdMi30qOHghJ6UtMouJgvamt7q/zdoIBaOQwuIqHIkMu/iRy2vHkUuB0bqBk4sd4tAhg0OUUJK6BNrG4mCEseCkjSz7rKA2s8RDlkE8bOEMu/yuNBqQAKQ5PHoMMRDiJy3AYoPpkZBo86WS/lNRrsqqeONvmK9eV1QG8i8).
[Answer]
# [J](http://jsoftware.com/), ~~42~~ 31 bytes
```
(1{]) ::0[([+[:I.{=}.)5 p:i.@*:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/NQyrYzUVrKwMojWitaOtPPWqbWv1NE0VCqwy9Ry0rP5rcnH5OekphGekFqUq@CqkVmQWlxQrcKUmZ@QraFinaarZKRiaKpgZKpiYmSpYmphClPvlw9WiKjVSMDFSMDP6DwA "J – Try It Online")
Returns `0` if no \$M\$ exists. 
## Explanation :
(of the previous version)
The argument is `n`
```
                              @*:   find n^2 and   
                            i.      make a list 0..n^2-1
                           +        to each number in the list add
                          ]         the argument (n) -> list n..n^2+n-1
                      5 p:          find the totient of each number in the above list
                    @(           )  use the above result as an argument for 
          (        )                the next verb 
                =                   compare
                 {.                 the head of the list
               ]                    with each number in the list  
           [:I.                     get the indices where the above is true
 (    ) ::0                         try the verb in parentheses and return 0 if it failed
   1{]                              get the second (0-based indexing) element
  +                                 and add n to it
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~21~~ 19 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
ôU ÅæÈo èjX ¥Uo èjU
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=9FUgxebIbyDoalggpVVvIOhqVQ&input=WzE1LDYxLDQ2NSw5NDUsMTIsNDIsNjJdClsxNiw3Nyw0ODIsOTYyLG4sbixuXQotbQotUQ)
```
ôU                      range [input ...input + input]
   Å                    cut off first element 
      æÈ                return the first element to return a truty value when passed to:
        o               range [0... next element]
          è             number of elements that are..
           jX           coprime to next element.
              ¥         equal to
               Uo èjU   num of coprimes of input 
```
Outputs `null` if no \$m\$ exists.
Thanks to @Shaggy for reminding me of ô() which gives the range needed
]