CSES Missing Number

Here is the link to the task: CSES - Missing Number

This is the code I wrote:
#include < iostream>
#include < vector>
#include < algorithm>

using namespace std;

int main(){
int n;
cin >> n;
vector v(n-1);
for(int i=0;i<n-1;i++){
cin >> v[i];
}
int missingNumber;
sort(v.begin(),v.end());

for(int j=1;j<(n-1);j++){
    if(v[j]!=v[j-1]+1){
        missingNumber = v[j-1]+1;
    }
}
cout << missingNumber;

}

When I submitted, it said I missed 3 test cases. How can I fix it?