Problem: You are standing in front of the room with great treasures. The only thing stopping you is the door with a push-button combination lock. This lock has d buttons with digits from 0 to d - 1. Whenever you press a button, it stays pushed down. You can not pop back up just one button, but there is a "RESET" button — pressing it pops up all other buttons. Initially, no buttons are pushed down.

The door instantly opens when some specific set of digits is pushed down. Sadly, you don't know the password for it. Having read the documentation for this specific lock, you found out that there are n possible passwords for this particular lock. 

Find the shortest sequence of button presses, such that all possible passwords appear at least once during its execution. Any shortest correct sequence of button presses will be accepted.

Input

The first line contains two integers d and n (1 ≤ d ≤ 10; 1 ≤ n ≤ 2^d - 1). Next n lines describe possible passwords. Each line contains a string s_i of d zeros and ones: for all j from 1 to d the j-th character is 1 iff the button with the digit j - 1 must be pushed down.

All strings s_i are different, and each string contains at least one 1.

Output

On the first line, print the number k — the minimum number of button presses. On the second line, print k tokens, describing the sequence. Whenever you press a button with a digit, print that digit. Whenever you press "RESET", print "R".

Examples

Input


2 2
10
11


Output


2
0 1 


Input


3 4
001
111
101
011


Output


6
2 0 R 1 2 0 

Note

In the second example, the sequence 1 2 R 2 0 1 is also possible.

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
struct Edge {int to, flow, cost;};
template < int N > struct MinCostMaxFlow
{
    int D[N], P[N];
    bool M[N];
    vector < int > vac;
    vector < int > Adj[N];
    vector < Edge > E, E2, E3;
    inline void Add(int v, int u, int w, int c)
    {
        Adj[v].pb(E.size());
        E.pb({u, w, c});
        Adj[u].pb(E.size());
        E.pb({v, 0, -c});
        E3.pb({u, w, c});
        E3.pb({v, 0, -c});
    }
    inline void Reset()
    {
        E.clear();
        for (Edge e : E3)
            E.pb(e);
        memset(D, 0, sizeof(D));
        memset(P, 0, sizeof(P));
        memset(M, 0, sizeof(M));
        vac.clear();
    }
    inline bool SPFA(int s, int t)
    {
        queue < int > qu;
        memset(D, 63, sizeof(D));
        memset(P, -1, sizeof(P));
        memset(M, 0, sizeof(M));
        D[s] = 0; qu.push(s);
        while (qu.size())
        {
            int v = qu.front();
            qu.pop(); M[v] = 0;
            for (int &id : Adj[v])
                if (E[id].flow && D[E[id].to] > D[v] + E[id].cost)
                {
                    P[E[id].to] = id;
                    D[E[id].to] = D[v] + E[id].cost;
                    if (!M[E[id].to])
                        qu.push(E[id].to), M[E[id].to] = 1;
                }
        }
        return (P[t] != -1);
    }
    inline pair < int , int > MaxFlow(int s, int t)
    {
        int Flow = 0, Cost = 0;
        while (SPFA(s, t))
        {
            int flow = INT_MAX, v = t;
            while (v != s)
                flow = min(flow, E[P[v]].flow), v = E[P[v]^1].to;
            v = t;
            while (v != s)
            {
                E[P[v]].flow -= flow,
                E[P[v]^1].flow += flow,
                v = E[P[v]^1].to;
            }
            Flow += flow;
            Cost += D[t] * flow;
        }
        return make_pair(Flow, Cost);
    }
    bool RollBack(int source, int v, int sink)
    {
        //printf("%d ==\n", v);
        if (v == sink)
            return 1;
        vac.pb(v);
        for (int id : Adj[v])
            if (id % 2 == 0 && E2[id ^ 1].flow)
            {
                E2[id ^ 1].flow --;
                return RollBack(source, E2[id].to, sink);
            }
        assert(source == v);
        return 0;
    }
    inline vector < pair < int , int > > ExtractCrap(int source, int sink, int flow)
    {
        E2.clear();
        for (Edge e : E)
            E2.pb(e);
        vector < pair < int , int > > stuff;
        vac.clear();
        //printf("%d ::::\n", (int)RollBack(source, sink));
        while (RollBack(source, source, sink))
        {
            flow--;
            stuff.pb({vac[1], vac.back()});
            vac.clear();
        }
        assert(flow == 0);
        return stuff;
    }
};
const int N = 1029, MXV = 3 * N, MXD = 11, INF = 1e9;
int n, d, X[N], up[N], dn[N], md[N], F[MXV], M[MXV];
int revup[MXV], revdn[MXV];
char S[MXD];
int main()
{
    scanf("%d%d", &d, &n);
    for (int i = 0; i < n; i ++)
    {
        scanf("%s", &S);
        for (int j = 0; j < d; j ++)
            X[i] += (S[j] - '0') << j;
    }
    sort(X, X + n);
    MinCostMaxFlow < N * 3 > G;
    int k = 1 << d;
    int ts = 0;
    int source = ts ++;
    int sink = ts ++;
    for (int i = 0; i < n; i ++)
        up[i] = ts ++, revup[up[i]] = i;
    for (int i = 0; i < k; i ++)
        md[i] = ts ++;
    for (int i = 0; i < n; i ++)
        dn[i] = ts ++, revdn[dn[i]] = i;
 
    for (int i = 0; i < k; i ++)
        for (int j = 0; j < d; j ++)
            if (!((i >> j) & 1))
                G.Add(md[i], md[i | (1 << j)], INF, 0);
    int defaultCost = -1;
    for (int i = 0; i < n; i ++)
        defaultCost += __builtin_popcount(X[i]) + 1;
    for (int i = 0; i < n; i ++)
    {
        G.Add(source, up[i], 1, -(__builtin_popcount(X[i]) + 1));
        G.Add(dn[i], sink, 1, 0);
        G.Add(md[X[i]], dn[i], 1, 0);
        for (int j = 0; j < d; j ++)
            if (!((X[i] >> j) & 1))
                G.Add(up[i], md[X[i] | (1 << j)], 1, 0);
    }
    // Simulate Maximum Flow Algorithm:
    int MinCost = INF, optimalK = -1;
    vector < pair < int , int > > stuff;
 
    int Flow = 0, Cost = 0, nowK = 0;
    while (G.SPFA(source, sink))
    {
        nowK ++;
        int flow = INT_MAX, v = sink;
        while (v != source)
            flow = min(flow, G.E[G.P[v]].flow), v = G.E[G.P[v]^1].to;
        v = sink;
        while (v != source)
        {
            G.E[G.P[v]].flow -= flow,
            G.E[G.P[v]^1].flow += flow,
            v = G.E[G.P[v]^1].to;
        }
        Flow += flow;
        Cost += G.D[sink] * flow;
        if (Cost < MinCost)
        {
            MinCost = Cost;
            optimalK = nowK;
        }
    }
    if (optimalK != -1)
    {
        G.Reset();
        Flow = 0, Cost = 0;
        nowK = 0;
        while (G.SPFA(source, sink) && nowK != optimalK)
        {
            nowK ++;
            int flow = INT_MAX, v = sink;
            while (v != source)
                flow = min(flow, G.E[G.P[v]].flow), v = G.E[G.P[v]^1].to;
            v = sink;
            while (v != source)
            {
                G.E[G.P[v]].flow -= flow,
                G.E[G.P[v]^1].flow += flow,
                v = G.E[G.P[v]^1].to;
            }
            Flow += flow;
            Cost += G.D[sink] * flow;
        }
        stuff = G.ExtractCrap(source, sink, Flow);
    }
    // Do stuff with that crap:
    memset(F, -1, sizeof(F));
    for (auto p : stuff)
        F[X[revup[p.first]]] = X[revdn[p.second]];
    if(optimalK == -1)
        MinCost = 0;
    printf("%d\n", MinCost + defaultCost);
    vector< vector<int> > alls;
    for (int i = 0; i < n; i ++)
        if (!M[X[i]])
        {
            vector<int> tmp;
            int now = X[i];
            for (int j = 0; j < d; j ++)
                if (now >> j & 1)
                    tmp.push_back(j);
            M[now] = 1;
            while (F[now] != -1)
            {
                int to = F[now]; M[to] = 1;
                for (int j = 0; j < d; j ++)
                    if ((now ^ to) >> j & 1)
                        tmp.push_back(j);
                now = to;
            }
            alls.push_back(tmp);
        }
    bool start = 0;
    for(auto v : alls){
        if(start)
            printf("R ");
        start = 1;
        for(int x : v)
            printf("%d ", x);
    }
    printf("\n");
    return 0;
}