Tiling problem . Why showing run time error?

import java.util.*;
public class Main {
public static void main(String agrsp[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++){
int n=sc.nextInt();
int m=sc.nextInt();
int ways=fun(n,m);
System.out.println(ways);
}
}
public static int fun(int n,int m){
if(n==0)
return 1;
if(n<0)
return 0;
int a=fun(n-1,m);
int b=fun(n-m,m);
return (a+b)%1000000007;
}
}

u need to do this using dynamic programming

since constraints are large u get run time error

so can my code be optimised or i have to think of totally different approach??