import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;

void main(){
    auto nm=readln.split.map!(to!int).array;
    auto m=nm[0];
    auto n=nm[1];
    int[][] abs;
    foreach(i;0..m)abs~=readln.split.map!(to!int).array;
    int[][] routes;
    routes~=[1];
    foreach(i;0..m-1){
        int[][] newRoutes;
        foreach(x;1..m+1){
            foreach(r;routes){
                if(r.find(x).empty)newRoutes~=(r~x);
            }
        }
        routes=newRoutes;
    }
    long res=0;
outer:foreach(r;routes){
          writeln(r);
          foreach(i;0..m-1){
            if(abs.find(r[i..i+2]).empty && abs.find([r[i+1],r[i]]).empty)continue outer;
          }
          ++res;
    }
      writeln(res);
}