https://www.acmicpc.net/problem/16956
r,c=map(int,input().split())
arr=[[0 for _ in range(c)] for _ in range(r)]
for i in range(r):
st=input()
for j in range(c):
arr[i][j]=st[j]
check=True
dx=[0,0,1,-1]
dy=[1,-1,0,0]
for i in range(r):
for j in range(c):
if arr[i][j]=='W':
for k in range(4):
x=i+dx[k]
y=j+dy[k]
if x>=0 and x<r and y>=0 and y<c:
if arr[x][y]=='.':
arr[x][y]='D'
elif arr[x][y]=='S':
check=False
print(0)
exit()
if check==False: print(0)
else:
print(1)
for i in range(r):
for j in range(c):
print(arr[i][j],end='')
print()