Simple Java Solution
Code\njava []\nclass Node\n{\n    int a,b;\n    public Node(int i,int j)\n    {\n       a=i;\n       b=j;\n    }\n}\nclass Solution {\n    public int minTimeToR
# Code\n```java []\nclass Node\n{\n    int a,b;\n    public Node(int i,int j)\n    {\n       a=i;\n       b=j;\n    }\n}\nclass Solution {\n    public int minTimeToReach(int[][] moveTime) {\n        int visited[][]=new int[moveTime.length][moveTime[0].length];\n        int f[][]=new int[moveTime.length][moveTime[0].length];\n        int v[][]=new int[moveTime.length][moveTime[0].length];\n        for(int i=0;i<visited.length;i++)\n        {\n            Arrays.fill(visited[i],-1);\n        }\n\n        visited[0][0]=1;\n        f[0][0]=0;\n        Queue<Node> q=new LinkedList<Node>();\n        int arr[][]=new int[moveTime.length][moveTime[0].length];\n        v[0][0]=1;\n        q.add(new Node(0,0));\n        while(q.size()>0)\n        {\n            Node node=q.poll();\n            int x=node.a;\n            int y=node.b;\n            v[x][y]=0;\n            int time=arr[x][y];\n            int flag=f[x][y];\n            //System.out.println(x+" "+y+" "+arr[x][y]+" "+flag);\n            if(x-1>=0)\n            {\n                if(visited[x-1][y]==-1)\n                {\n                    visited[x-1][y]=1;\n                    int tim=Math.max(moveTime[x-1][y],time);\n                    if(flag==0)\n                    {\n                       arr[x-1][y]=tim+1;\n                        f[x-1][y]=1;\n                       if(v[x-1][y]==0)\n                       {\n                          v[x-1][y]=1;\n                         \n                          q.add(new Node(x-1,y));\n                       }\n                    }\n                    else\n                    {\n                       arr[x-1][y]=tim+2;\n                         f[x-1][y]=0;\n                       if(v[x-1][y]==0)\n                       {\n                          v[x-1][y]=1;\n                         \n                        q.add(new Node(x-1,y));\n                       }\n                       \n                    } \n                }\n                else\n                {\n                     int tim=Math.max(moveTime[x-1][y],time);\n                     if(flag==0)\n                     {\n                        tim=tim+1;\n                     }\n                     else\n                     {\n                        tim=tim+2;\n                     }\n                     if(arr[x-1][y]>tim)\n                     {\n                        arr[x-1][y]=tim;\n                      \n                        if(flag==1)\n                        {\n                            f[x-1][y]=0;\n                            if(v[x-1][y]==0)\n                            {\n                                v[x-1][y]=1;\n                                \n                                q.add(new Node(x-1,y));\n                            }\n                        }\n                        else\n                        {\n                             f[x-1][y]=1;\n                            if(v[x-1][y]==0)\n                            {\n                                v[x-1][y]=1;\n                               \n                            q.add(new Node(x-1,y));\n                            }\n                        }\n                     }\n                }\n            }\n             if(y-1>=0)\n            {\n                if(visited[x][y-1]==-1)\n                {\n                    visited[x][y-1]=1;\n                    int tim=Math.max(moveTime[x][y-1],time);\n                    if(flag==0)\n                    {\n                        f[x][y-1]=1;\n                       arr[x][y-1]=tim+1;\n                       if(v[x][y-1]==0)\n                       {\n                        v[x][y-1]=1;\n                        \n                       q.add(new Node(x,y-1));\n                       }\n                    }\n                    else\n                    {\n                       arr[x][y-1]=tim+2;\n                        f[x][y-1]=0;\n                       if(v[x][y-1]==0)\n                       {\n                        v[x][y-1]=1;\n                       q.add(new Node(x,y-1));\n                       }\n                    } \n                }\n                else\n                {\n                     int tim=Math.max(moveTime[x][y-1],time);\n                     if(flag==0)\n                     {\n                        tim=tim+1;\n                     }\n                     else\n                     {\n                        tim=tim+2;\n                     }\n                     if(arr[x][y-1]>tim)\n                     {\n                        \n                        arr[x][y-1]=tim;\n                        if(flag==1)\n                        {\n                              f[x][y-1]=0;\n                             if(v[x][y-1]==0)\n                             {\n                                v[x][y-1]=1;\n                            q.add(new Node(x,y-1));\n                             }\n                        }\n                        else\n                        {\n                              f[x][y-1]=1;\n                            if(v[x][y-1]==0)\n                            {\n                                v[x][y-1]=1;\n                                q.add(new Node(x,y-1));\n                            }\n                        }\n                     }\n                }\n            }\n             if(x+1<visited.length)\n            {\n                if(visited[x+1][y]==-1)\n                {\n                    visited[x+1][y]=1;\n                    int tim=Math.max(moveTime[x+1][y],time);\n                    if(flag==0)\n                    {\n                       arr[x+1][y]=tim+1;\n                        f[x+1][y]=1;\n                        if(v[x+1][y]==0)\n                        {\n                            v[x+1][y]=1;\n                           q.add(new Node(x+1,y));\n                        }\n                    }\n                    else\n                    {\n                       arr[x+1][y]=tim+2;\n                       f[x+1][y]=0;\n                       if(v[x+1][y]==0)\n                        {\n                            v[x+1][y]=1;\n                           q.add(new Node(x+1,y));\n                        }\n                    } \n                }\n                else\n                {\n                     int tim=Math.max(moveTime[x+1][y],time);\n                     if(flag==0)\n                     {\n                        tim=tim+1;\n                     }\n                     else\n                     {\n                        tim=tim+2;\n                     }\n                     if(arr[x+1][y]>tim)\n                     {\n                        \n                        arr[x+1][y]=tim;\n                        if(flag==1)\n                        {\n                            f[x+1][y]=0;\n                           if(v[x+1][y]==0)\n                            {\n                                v[x+1][y]=1;\n                            q.add(new Node(x+1,y));\n                            }\n                        }\n                        else\n                        {\n                            f[x+1][y]=1;\n                           if(v[x+1][y]==0)\n                            {\n                                v[x+1][y]=1;\n                            q.add(new Node(x+1,y));\n                            }\n                        }\n                     }\n                }\n            }\n             if(y+1<visited[0].length)\n            {\n                if(visited[x][y+1]==-1)\n                {\n                    visited[x][y+1]=1;\n                    int tim=Math.max(moveTime[x][y+1],time);\n                    if(flag==0)\n                    {\n                       arr[x][y+1]=tim+1;\n                       f[x][y+1]=1;\n                       if(v[x][y+1]==0)\n                        {\n                            v[x][y+1]=1;\n                           q.add(new Node(x,y+1));\n                        }\n                    }\n                    else\n                    {\n                       arr[x][y+1]=tim+2;\n                       f[x][y+1]=0;\n                       if(v[x][y+1]==0)\n                        {\n                            v[x][y+1]=1;\n                           q.add(new Node(x,y+1));\n                        }\n\n                      \n                    } \n                }\n                else\n                {\n                     int tim=Math.max(moveTime[x][y+1],time);\n                     if(flag==0)\n                     {\n                        tim=tim+1;\n                     }\n                     else\n                     {\n                        tim=tim+2;\n                     }\n                     if(arr[x][y+1]>tim)\n                     {\n                        \n                        arr[x][y+1]=tim;\n                        if(flag==1)\n                        {\n                          f[x][y+1]=0;\n                       if(v[x][y+1]==0)\n                        {\n                            v[x][y+1]=1;\n                           q.add(new Node(x,y+1));\n                        }\n                        }\n                        else\n                        {\n                           f[x][y+1]=1;\n                            if(v[x][y+1]==0)\n                                {\n                                    v[x][y+1]=1;\n                                q.add(new Node(x,y+1));\n                                }\n                            }\n                     }\n                }\n            }\n        }\n     \n      \n        return arr[visited.length-1][visited[0].length-1];\n\n        \n    }\n}\n```
['Java']