```
public class Solution {
public int canCompleteCircuit(int[] gas, int[] cost) {
int num=0;
int m=gas.length;
int count=0;
for(int i=0;i<m;i++){
for(int j=i;;){
if(j>m-1){
j=0;
}
num=num+gas[j];
if(num-cost[j]<0){
num=0;
break;
}else{
num=num-cost[j];
count++;
j++;
}
if(count==m){
return i;
}
}
}
return -1;
}
```

}