Fire propagation simulator Suppose we have a matrix like this:

11111
12221
12321
12221
11111


This matrix represents a terrain, and each cell represents a portion of terrain. The number in each cell represents the time the portion of terrain needs to be completely burnt (in minutes, if a measurement unit is needed), according to its combustibility. If a fire starts at any given position (cell), that cell needs to be completely burnt before the fire propagates to the adjacent cells (horizontal and vertical only, not diagonal). So, if a fire is started at the center position, the fire needs:

11111        11111        11111        11011        10001        00000
12221  3 m.  12221  2 m.  12021  1 m.  11011  1 m.  00000  1 m.  00000
12321 -----&gt; 12021 -----&gt; 10001 -----&gt; 00000 -----&gt; 00000 -----&gt; 00000
12221        12221        12021        11011        00000        00000
11111        11111        11111        11011        10001        00000


Explanation:


Fire starts at [2,2] (0-based), which has a burn time of 3.
After 3 minutes, [1,2],[2,1],[2,3],[3,2] start to burn.
After 2 minutes, those cells end burning and fire propagates to all adjacent cells, but [0,2],[2,0],[2,4],[0,4] need only 1 more minute to burn, so
After 1 minute, those cells are burnt and the cell propagates to their adjacent cells.
After 1 more minute, the rest of cells from step 3 end burning and fire propagates to their adjacent cells (that are already burnt, so nothing happens).
After 1 last minute, fire ends burning the whole terrain.


So the solution to that case is 8 minutes. If the fire starts in the top leftmost cell [0,0]:

11111     01111     00111     00011     00001     00000
12221  1  12221  1  02221  1  01221  1  00121  1  00011   1
12321 --&gt; 12321 --&gt; 12321 --&gt; 02321 --&gt; 01321 --&gt; 00321  --&gt;
12221     12221     12221     12221     02221     01221
11111     11111     11111     11111     11111     01111

00000     00000     00000     00000     00000
00000  1  00000  1  00000  1  00000  1  00000
00221 --&gt; 00110 --&gt; 00000 --&gt; 00000 --&gt; 00000
00221     00121     00020     00010     00000
00111     00011     00001     00000     00000


So now the total time is 10 minutes.

The challenge

Given a NxM matrix (N>0, M>0) of integer values that represent the time every cell needs to be completely consumed, write the shortest program/function that takes that matrix and a pair of integers with the position the fire starts in, and returns/prints the time needed for the fire to completely consume the whole terrain.


Every cell will have a positive (non-zero) burn time. You cannot assume a maximum value for the cells.
The matrix does not need to be square nor symmetric.
The matrix can be 0-indexed or 1-indexed, as you like.
The position can be given as a single parameter with a tuple of integers, two separate parameters of whatever other reasonable format.
The dimensions of the matrix cannot be specified as input parameters.
You do not need to output every intermediate step, just the amount of time asked. But I won't complain if the steps are visualized in any way.


Another example:

Fire starts at [1,1] (a '&gt;' represents a minute):

4253   4253   4253   4153   4043   3033   2023    0001   0000
2213 &gt; 2113 &gt; 2013 &gt; 1003 &gt; 0002 &gt; 0001 &gt; 0000 &gt;&gt; 0000 &gt; 0000 
1211   1211   1211   1111   1001   0000   0000    0000   0000

Output: 9


This is code-golf, so may the shortest program for each language win!
Matlab, 235 257 190 182 178 bytes

Input: Matrix A, 1x2 vector p containing the starting coordinates.

function t=F(A,p)
[n,m]=size(A);x=2:n*m;x(mod(x,n)==1)=0;B=diag(x,1)+diag(n+1:n*m,n);k=sub2ind([n m],p(1),p(2));t=max(distances(digraph(bsxfun(@times,((B+B')~=0),A(:))'),k))+A(k)


Explanation:

Instead of simulating the the fire propagation, we can also understand this as a "find the longest shortest path" problem. The matrix is converted into a weighted directed graph. The weights of the paths to a single node correspond to the time to burn said node. E.g. for a matrix

5   7   7   10
5   2   2   10
4   5   2   6


we get the connected graph:



Where node 1 is the upper left matrix element and node 12 the lower right element. Given starting coordinates p, the shortest path to all other nodes is calculated. Then the length of the longest path of those shortest paths + the time to burn the initial node equals to the time to burn the whole matrix.

Ungolfed and commented version with sample starting values:

% some starting point
p = [3 2];
% some random 5x6 starting map, integers between 1:10
A = randi(10,5,6); 

function t=F(A,p)
% dimensions of A
[n,m] = size(A);
% create adjacency matrix
x=2:n*m;
x(mod(x,n)==1)=0;
B = diag(x,1)+diag(n+1:n*m,n);
B = B+B';
B = bsxfun(@times,(B~=0),A(:))';
% make graph object with it
G = digraph(B);
% starting node
k = sub2ind([n m], p(1), p(2));
% calculate the shortest distance to all nodes from starting point
d = distances(G,k);
% the largest smallest distance will burn down last. Add burntime of initial point
t = max(d)+A(k);