Searching in a 2D Matrix (I've used Staircase search)

Can u please tell me what’s wrong in my code (1 out of 3 test cases are passed)

#include
using namespace std;
int main() {
int n,m;
int a[n][m];
int target;

//Taking Array Input
for(int i = 0;i<n;i++){
	for(int j = 0; j< m; j++){
		cin >> a[i][j];
	}
}
cin >> target;

int right = m -1;
int left = 0;


bool flag = false;

//Staircase search
while(left < n && right >= 0){
	if(target == a[left][right]){
		flag = true;
		break;
	}
	else if(target > a[left][right]){
		left++;
	}
	else{
		right--;
	}
}
if(flag){
	cout<<"1"<<endl;
}
else{
	cout<<"0"<<endl;
}

return 0;

}