Where will the gem-picking robot end up? Related puzzle: Pathfinder (available on Puzzle Picnic)
Background
A robot is standing on a cell of a rectangular grid, where each cell has one or more gems except for the one with the robot. The robot can move to a horizontally or vertically adjacent cell in one step, and it picks up one gem from the cell it steps on.
The robot is programmed with which cell to choose for its next step, based on the number of gems each adjacent cell contains. The program is in the form of a &gt; b &gt; c &gt; ... &gt; z, which means that the robot prefers to move into the cell with a gems, followed by one with b gems, and so on. Any such program contains positive integers from 1 to n exactly once, where n is the length of the program. The robot will never move into any cell with no gems.
If there are multiple highest-priority cells around the robot, or all the cells around it are empty, it will get stuck at that point.
For example, if its program is 1 &gt; 3 &gt; 2 (meaning, it prefers the cell with only one gem the most, followed by the one with 3 gems, and then 2 gems) and the current state looks like this (R is the robot, the numbers are gems):
0 3 2
2 R 1
1 2 3

Then it will choose the cell on its right because 1 has the highest priority. Assuming the cell with R is empty, it will continue moving down, left, left, right, right, then get stuck since the cells around it have no gems left.
0 3 2     0 3 2     0 3 2     0 3 2     0 3 2     0 3 2     0 3 2
2 R 1 --&gt; 2 0 R --&gt; 2 0 0 --&gt; 2 0 0 --&gt; 2 0 0 --&gt; 2 0 0 --&gt; 2 0 0
1 2 3     1 2 3     1 2 R     1 R 2     R 1 2     0 R 2     0 0 R
       R         D         L         L         R         R

Using the 1 &gt; 3 &gt; 2 program, it will get stuck at any of the following cases:
0 R 0  # all adjacent cells are empty
2 0 1
1 2 2

3 1 0  # there are two 1s around the robot, so it can't decide where to go
2 R 1
1 0 2

Challenge
Given the initial state of the entire grid and the robot's program, find the position (horizontal and vertical coordinates) in the grid where the robot will eventually get stuck.
The initial state contains the numbers between 1 and 9 inclusive, except for a single 0 which denotes the initial position of the robot. The program is guaranteed to contain all positive numbers that appear in the grid, and the program is always valid (contains each of 1 to the maximum value on the grid exactly once).
You can take the input (grid and program) in any suitable format, and output the coordinates in any sensible way.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
In the example I/O provided, the program has the highest precedence coming first, and the coordinates are 1-based.
Grid:
0 2 1
3 3 2
1 1 3
Program: 3 1 2
Result: 2nd row, 3rd column (Path: DRDRUUD)

Grid: (one row)
0 3 2 3 1 4 4
Program: 4 2 3 1
Result: 1st row, 7th column (Path: RRLRRRRRLRLRLR)

Grid:
0 1 3
3 1 3
2 1 2
Program: 3 1 2
Result: 3rd row, 3rd column (Path: DRRULRDD)

Grid:
2 3 1 2 1
2 0 3 2 2
1 1 3 1 1
Program: 1 3 2
Result: 2nd row, 4th column (Path: DLUUDURRDDRRUULD)

Same grid as above, Program: 3 2 1
Result: 2nd row, 2nd column (Stuck at zero moves)
Python 2, 205 198 bytes

def s(g,w,r):
 p=g.index(0)
 while 1:
    a=[((r+[0]).index(v),n)for n,v in enumerate(g)if(abs(n-p)in[1,w])&gt;(p-n)%w*(p/w!=n/w)];m,n=min(a)
    if~-sum(k[0]==m&lt;len(r)for k in a):return p/w,p%w
    p=n;g[p]-=1

-6 bytes thanks to @ovs
-1 byte thanks to @user202729
Try it online!
Take the input grid as a flattened list with width also passed. Outputs 0-indexed (x,y) coordinates of the final position (I doubt index in the flattened list would be acceptable).
Explanation:
# Function of flattened grid g, width w, pRiorities r
def s(g,w,r):
    # starting position p
    p = g.index(0)
    while 1:
        a = [
            # pair (priority rank of the cell, cell id)
            # priority rank is n for v=0
            ((r+[0]).index(v),n)
            # for each adjacent cell id n with v gems
            for n,v in enumerate(g) if abs(n-p) in [1,w] and (p%w==n%w or p/w==n/w)
        ];
        # min comparison is done by tuple, so it selects one with minimum priority rank
        # m = min priority rank; n = corresponding cell id
        m,n = min(a)
        if sum( # how many adjacent cells
            k[0]==m # have priority rank equal to m
            &lt;len(r) # and the cell value is not 0
            for k in a
        ) ^ 1: # If this count is not 1, then the robot is stuck; return
            return(p/w, p%w)
        # Otherwise, continue with updated position,
        p = n;
        # and take one gem
        g[p] -= 1