18 BUS ERROR. CODE WORKING PERFECTLY IN DEV C++

Respected sir
the following code is working perfectly in dev c++. Hoever its showing some error here. Could you please help me with it.
#include
using namespace std;
int main() {
int N,M,x=0;
int a[N][M];
cin>>N>>M;
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
cin>>a[i][j];
}
}
cin>>x;
int j=M-1;
int i=0;

while(i<N && j>=0)
{ 

if(a[i][j]==x)
{
	x=1;
	break;

}
else if(a[i][j]>x)
{
    	j--;
    	
}
else 
i++;

}

if(x==1)
{
cout<<1;
}
else cout<<0;
return 0;
}

Thanks
Manah Verma

hello @mverma_be19

interchnage the position of these two lines. i.e first read n ,m and then declare array.

Now its showing segmentation fault

pls save ur code here->https://ide.codingblocks.com/
and share the link with me.