program ideone;
uses Math;
Const smax = 99; kmax = 99;
Type arr2d = array[0..smax, 0..kmax] of smallint; simple = array[0..smax] of smallint;
Var data:arr2d; i, j, n, m, count:smallint;
procedure writeArr(arr:simple; count:smallint);
Var i:smallint;
begin
for i:=0 to count-1 do write(arr[i], ' ');
writeln();
end;
function isMersenNum(num:smallint):boolean;
Var t:smallint;
begin
t:=num+1;
while (floor(t/2)=t/2) and ((t/2)>1) do begin
t := floor(t/2);
end;
if t/2 = 1 then isMersenNum := True else isMersenNum:=False;
end;
function processData(data:arr2d):simple;
Var res:simple; i, j:smallint;
begin
count:=0;
for i:=0 to n-1 do for j:=0 to m-1 do if isMersenNum(data[i][j]) = True then begin
res[count]:=data[i][j];
count:=count+1;
end;
processData:=res;
end;
begin
read(n, m);
for i:=0 to n-1 do for j:=0 to m-1 do read(data[i][j]);
writeArr(processData(data), count);
end.
cHJvZ3JhbSBpZGVvbmU7Cgp1c2VzIE1hdGg7CgpDb25zdCBzbWF4ID0gOTk7IGttYXggPSA5OTsgClR5cGUgYXJyMmQgPSBhcnJheVswLi5zbWF4LCAwLi5rbWF4XSBvZiBzbWFsbGludDsgc2ltcGxlID0gYXJyYXlbMC4uc21heF0gb2Ygc21hbGxpbnQ7ClZhciBkYXRhOmFycjJkOyBpLCBqLCBuLCBtLCBjb3VudDpzbWFsbGludDsKIApwcm9jZWR1cmUgd3JpdGVBcnIoYXJyOnNpbXBsZTsgY291bnQ6c21hbGxpbnQpOwpWYXIgaTpzbWFsbGludDsKYmVnaW4KCWZvciBpOj0wIHRvIGNvdW50LTEgZG8gd3JpdGUoYXJyW2ldLCAnICcpOwoJd3JpdGVsbigpOwplbmQ7CgpmdW5jdGlvbiBpc01lcnNlbk51bShudW06c21hbGxpbnQpOmJvb2xlYW47ClZhciB0OnNtYWxsaW50OwpiZWdpbgoJdDo9bnVtKzE7Cgl3aGlsZSAoZmxvb3IodC8yKT10LzIpIGFuZCAoKHQvMik+MSkgZG8gYmVnaW4KCQl0IDo9IG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