easy
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int minTimeToReach(vector<vector<int>>& moveTime) {
        int n=moveTime.size();
        int m=moveTime[0].size();
        vector<vector<int>> dis(n,vector<int>(m,INT_MAX));
        dis[0][0]=0;
        priority_queue<pair<int,pair<int,pair<int,int>>>,vector<pair<int,pair<int,pair<int,int>>>>,greater<>> pq;
        pq.push({0,{2,{0,0}}});
        vector<int> row={0,1,0,-1};
            vector<int> col={1,0,-1,0};
            
        while(!pq.empty()){
            int t=pq.top().first;
            int x=pq.top().second.second.first;
            int y=pq.top().second.second.second;
            int p=pq.top().second.first;
            pq.pop();
            if(p==1){
                p=2;
            }
            else{
                p=1;
            }
            for(int i=0;i<4;i++){
              int  nx=x+row[i];
              int  ny=y+col[i];
              int nt;
                if(nx>=0 && nx<n && ny>=0 && ny<m ){
                    
                    if(t>=moveTime[nx][ny] ){
                        nt=t+p;
                    }
                    else {
                          nt=moveTime[nx][ny]+p;
                       
                    }
                     if(nt<dis[nx][ny]){
                    pq.push({nt,{p,{nx,ny}}});
                    dis[nx][ny]=nt;
                }
                }
               
            }
          
        }
        return dis[n-1][m-1];
    }
};
```
['C++']