```
class Solution {
public:
int canCompleteCircuit(vector<int> &gas, vector<int> &cost) {
int loc = 0;
int sum=0;
int min=INT_MAX;
//find the minimum
for(int i =0; i<gas.size(); ++i){
sum+=gas[i]-cost[i];
if(sum<min){
min = sum;
loc=i;
}
}
if(sum>=0) return (loc+1)%gas.size();
else return -1;
}
};
```