m,n = list(map(int,input().split())) if m == 1: print('*'*n,sep='') else: print('*'*m,'\n',('*'+" "*(n-2)+'*\n')*(m-2),'*'*m,sep='')