R9 -- Found At Last

i am having one wrong answer in the first test case ,all other test cases are working for me.
I have tested and applied all the constraints.
So kindly please tell me the error

#include
using namespace std;
int last(int *a,int n,int m)
{
if(n==0)
{
return -1;
}
if(a[n]==m)
{
return n;
}
else
{
return last(a,n-1,m);
}
}
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int m;
cin>>m;
int k;
k=last(a,n,m);
cout<<k;
return 0;
}

Your code is not producing correct answer for following test case,
1
8
8
Expected answer : 0
Your answer : -1
Try to use some better approach .