Paths & Wasting Time Premise

So recently I was about half an hour early to an appointment, and decided to wait outside. I also determined that it would look strange if I just stood motionlessly in front of the house. Therefore, I decided to go on a quick walk, within a limited area. I also concluded that if I started walking in circles that would make it obvious that I was loitering. So I was inspired to create my first Code Golf challenge.

Specification

You will be given a list, a map of the area, which will contain either " " or "#", which represent free spaces and obstacles of some sort. Free spaces can only be crossed once, and it takes 1 minute to cross it. Your initial position will be signified with a "@" per roguelike tradition, and the target will be represented with a "$" because that's what you're going to lose there. You will also be given an integer which will represent how many minutes you have to waste before not seeming as if you were intruding. When you land on the "$", it will have to have been the exact amount minutes (so if you were counting down, it will have to be 1 on an adjacent tile, and be 0 on the tile). It will always be possible to reach the destination. Your program or function will have to return a list showing the shortest path with &lt;, >, ^, and v to represent the four possible directions.

Examples

Input:

[[" ", " ", " ", " "],
 ["@", " ", " ", "$"],
 [" ", " ", " ", " "],
 [" ", " ", " ", " "]]


and

5


Ouput:

[["&gt;", "&gt;", "&gt;", "v"],
 ["^", " ", " ", "$"],
 [" ", " ", " ", " "],
 [" ", " ", " ", " "]]


Input:

[[" ", "#", " ", " ", " "],
 [" ", "#", " ", " ", " "],
 ["@", "#", " ", "$", " "],
 [" ", " ", " ", " ", " "],
 [" ", "#", " ", " ", " "],
 [" ", "#", " ", " ", " "]]


and

7


Output:

[[" ", "#", " ", " ", " "],
 [" ", "#", "&gt;", "v", " "],
 ["v", "#", "^", "$", " "],
 ["&gt;", "&gt;", "^", " ", " "],
 [" ", "#", " ", " ", " "],
 [" ", "#", " ", " ", " "]]


Input:

[[" ", "#", " ", " ", " "],
 [" ", "#", " ", " ", " "],
 ["@", "#", " ", "$", " "],
 [" ", " ", " ", " ", " "],
 [" ", "#", " ", " ", " "],
 [" ", "#", " ", " ", " "]]


and

17


Output:

[[" ", "#", " ", "v", "&lt;"],
 [" ", "#", " ", "v", "^"],
 ["v", "#", " ", "$", "^"],
 ["&gt;", "&gt;", "v", "&gt;", "^"],
 [" ", "#", "v", "^", "&lt;"],
 [" ", "#", "&gt;", "&gt;", "^"]]


Rules


Standard loopholes apply
Each tile must only be moved over once
The exact amount of time must be spent on the board
Only one path needs to be displayed in the case of multiple paths
This is a code golfing question so shortest answer wins
As per user202729's question in the comments, you may assume valid input.


Add a comment if any further clarification is required
JavaScript (ES6), 171 bytes
Takes input in currying syntax (a)(n). Outputs by modifying the input matrix.

a=&gt;g=(n,y=a[F='findIndex'](r=&gt;~(i=r[F](v=&gt;v&gt;'?'))),x=i,R=a[y])=&gt;!n--|[-1,0,1,2].every(d=&gt;(R[x]='&lt;^&gt;v'[d+1],(c=(a[Y=y+~-d%2]||0)[X=x+d%2])&lt;1?g(n,Y,X):n|c!='$')&amp;&amp;(R[x]=' '))

Try it online!
Commented
a =&gt;                           // a[] = input matrix
g = (                          // g = recursive function taking:
  n,                           //   n = number of remaining moves
                               //   (x, y) = current coordinates, initialized as follows:
  y = a[F = 'findIndex'](r =&gt;  //     y = index of the row containing the starting point,
    ~(i = r[F](v =&gt; v &gt; '?'))  //         found by iterating over all rows r until we
  ),                           //         find some i such that r[i] &gt; '?'
  x = i,                       //     x = index of the column of the starting point
  R = a[y]                     //   R[] = current row
) =&gt;                           //
  !n-- |                       // decrement n; force failure if we're out of moves
  [-1, 0, 1, 2].every(d =&gt;     // for each direction d, where -1 = left, 0 = up,
    (                          // 1 = right and 2 = down:
      R[x] = '&lt;^&gt;v'[d + 1], (  //   update the current cell with the direction symbol
        c = (                  //   c = content of the new cell at (X, Y) with:
          a[Y = y + ~-d % 2]   //     Y = y + dy
          || 0                 //     (use a dummy value if this row does not exist)
        )[X = x + d % 2]       //     X = x + dx
      ) &lt; 1 ?                  //   if c is a space:
        g(n, Y, X)             //     we can go on with a recursive call
      :                        //   else:
        n | c != '$'           //     return false if n = 0 and we've reached the target
    ) &amp;&amp;                       //   unless the above result is falsy,
    (R[x] = ' ')               //   restore the current cell to a space
  )                            // end of every()