#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int i, j, N, M, m, lastc, c, flag;
  char ans = 'S';
  scanf("%d%d", &N, &M);
  for (lastc = -1, i = 0; i < N; i++) {
    for (flag = 1, c = 0, j = 0; j < M; j++) {
      scanf("%d", &m);
      if (m == 0 && flag)
        c++;
      else
        flag = 0;
    }
    if (c <= lastc && c < M) {
      ans = 'N';
      break;
    }
    lastc = c;
  }
  printf("%c\n", ans);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x53,-0x25(%rbp)
lea    0xec6(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1207 <main+0xe7>
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d2 <main+0xb2>
lea    0xe77(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11b8 <main+0x98>
cmpl   $0x0,-0x24(%rbp)
je     11b8 <main+0x98>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11bf <main+0x9f>
movl   $0x0,-0x24(%rbp)
jmp    11c4 <main+0xa4>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <main+0x58>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11f3 <main+0xd3>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f3 <main+0xd3>
movb   $0x4e,-0x25(%rbp)
jmp    1207 <main+0xe7>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1157 <main+0x37>
lea    0xdf7(%rip),%rdi
movsbl -0x25(%rbp),%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    $0x53,%al
cmpl   $0x0,0xc(%rsp)
jle    11d1 <main+0xb1>
mov    $0xffffffff,%ebp
mov    0x8(%rsp),%eax
lea    0xe9f(%rip),%r14
lea    0x14(%rsp),%rbx
xor    %r12d,%r12d
jmp    117b <main+0x5b>
nopl   (%rax)
add    $0x1,%r12d
cmp    0xc(%rsp),%r12d
jge    11cf <main+0xaf>
mov    %ebp,0x10(%rsp)
xor    %ebp,%ebp
test   %eax,%eax
jle    11c1 <main+0xa1>
mov    $0x1,%r13d
xor    %r15d,%r15d
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x14(%rsp)
sete   %al
test   %r13d,%r13d
setne  %cl
and    %al,%cl
movzbl %cl,%r13d
add    %r13d,%ebp
add    $0x1,%r15d
mov    0x8(%rsp),%eax
cmp    %eax,%r15d
jl     1190 <main+0x70>
cmp    0x10(%rsp),%ebp
jg     1170 <main+0x50>
cmp    %eax,%ebp
jge    1170 <main+0x50>
mov    $0x4e,%al
jmp    11d1 <main+0xb1>
mov    $0x53,%al
movzbl %al,%esi
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %1
store i8 83, i8* %10
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
store i32 -1, i32* %7
store i32 0, i32* %2
br label %12
12: ; preds = %47, %0
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %50
16: ; preds = %12
store i32 1, i32* %9
store i32 0, i32* %8
store i32 0, i32* %3
br label %17
17: ; preds = %33, %16
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %32
31: ; preds = %25, %21
store i32 0, i32* %9
br label %32
32: ; preds = %31, %28
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %17
36: ; preds = %17
%37 = load i32, i32* %8
%38 = load i32, i32* %7
%39 = icmp sle i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i32, i32* %8
%42 = load i32, i32* %5
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %40
store i8 78, i8* %10
br label %50
45: ; preds = %40, %36
%46 = load i32, i32* %8
store i32 %46, i32* %7
br label %47
47: ; preds = %45
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %12
50: ; preds = %44, %12
%51 = load i8, i8* %10
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %41
10: ; preds = %0
%11 = load i32, i32* %2
br label %15
12: ; preds = %34
%13 = load i32, i32* %1
%14 = icmp slt i32 %40, %13
br i1 %14, label %15, label %41
15: ; preds = %10, %12
%16 = phi i32 [ %35, %12 ], [ %11, %10 ]
%17 = phi i32 [ %36, %12 ], [ -1, %10 ]
%18 = phi i32 [ %40, %12 ], [ 0, %10 ]
%19 = icmp sgt i32 %16, 0
br i1 %19, label %20, label %34
20: ; preds = %15, %20
%21 = phi i32 [ %29, %20 ], [ 1, %15 ]
%22 = phi i32 [ %30, %20 ], [ 0, %15 ]
%23 = phi i32 [ %31, %20 ], [ 0, %15 ]
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 0
%27 = icmp ne i32 %21, 0
%28 = and i1 %27, %26
%29 = zext i1 %28 to i32
%30 = add nuw nsw i32 %22, %29
%31 = add nuw nsw i32 %23, 1
%32 = load i32, i32* %2
%33 = icmp slt i32 %31, %32
br i1 %33, label %20, label %34
34: ; preds = %20, %15
%35 = phi i32 [ %16, %15 ], [ %32, %20 ]
%36 = phi i32 [ 0, %15 ], [ %30, %20 ]
%37 = icmp sle i32 %36, %17
%38 = icmp slt i32 %36, %35
%39 = select i1 %37, i1 %38, i1 false
%40 = add nuw nsw i32 %18, 1
br i1 %39, label %41, label %12
41: ; preds = %12, %34, %0
%42 = phi i8 [ 83, %0 ], [ 78, %34 ], [ 83, %12 ]
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext %42)
ret i32 0
}