description: Andi and Budi were given an assignment to tidy up their bookshelf of n books. Each book is represented by the book title — a string s_i numbered from 1 to n, each with length m. Andi really wants to sort the book lexicographically ascending, while Budi wants to sort it lexicographically descending.
  
  Settling their fight, they decided to combine their idea and sort it asc-desc-endingly, where the odd-indexed characters will be compared ascendingly, and the even-indexed characters will be compared descendingly.
  
  A string a occurs before a string b in asc-desc-ending order if and only if in the first position where a and b differ, the following holds:
  
    * if it is an odd position, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b; 
    * if it is an even position, the string a has a letter that appears later in the alphabet than the corresponding letter in b. 
  
  Input
  
  The first line contains two integers n and m (1 ≤ n ⋅ m ≤ 10^6).
  
  The i-th of the next n lines contains a string s_i consisting of m uppercase Latin letters — the book title. The strings are pairwise distinct.
  
  Output
  
  Output n integers — the indices of the strings after they are sorted asc-desc-endingly.
  
  Example
  
  Input
  
  
  5 2
  AA
  AB
  BB
  BA
  AZ
  
  
  Output
  
  
  5 2 1 3 4
  
  Note
  
  The following illustrates the first example.
  
  <image>
solution: import java.io.*;
  import java.util.*;
  
  public class compar{
      //--------------------------INPUT READER--------------------------------//
      static class fs {
          public BufferedReader br;
          StringTokenizer st = new StringTokenizer("");
  
          public fs() { this(System.in); }
          public fs(InputStream is) {
              br = new BufferedReader(new InputStreamReader(is));
          }
          String next() {
              while (!st.hasMoreTokens()) {
                  try { st = new StringTokenizer(br.readLine()); }
                  catch (IOException e) { e.printStackTrace(); }
              }
              return st.nextToken();
          }
  
          int ni() { return Integer.parseInt(next()); }
          long nl() { return Long.parseLong(next()); }
          double nd() { return Double.parseDouble(next()); }
          String ns() { return next(); }
  
          int[] na(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) a[i] = ni();
              return a;
          }
  
          long[] nal(int n) {
              long[] l = new long[n];
              for(int i = 0; i < n; i++) l[i] = nl();
              return l;
          }
      }
      //-----------------------------------------------------------------------//
  
      //---------------------------PRINTER-------------------------------------//
      static class Printer {
          static PrintWriter w;
          public Printer() {this(System.out);}
          public Printer(OutputStream os) {
              w = new PrintWriter(os);
          }
          public void p(int i) {w.println(i);};
          public void p(long l) {w.println(l);};
          public void p(double d) {w.println(d);};
          public void p(String s) { w.println(s);};
          public void pr(int i) {w.println(i);};
          public void pr(long l) {w.print(l);};
          public void pr(double d) {w.print(d);};
          public void pr(String s) { w.print(s);};
          public void pl() {w.println();};
          public void close() {w.close();};
      }
      //------------------------------------------------------------------------//
  
      //--------------------------VARIABLES------------------------------------//
      static fs sc = new fs();
      static OutputStream outputStream = System.out;
      static Printer w = new Printer(outputStream);
      //-----------------------------------------------------------------------//
  
      //--------------------------ADMIN_MODE-----------------------------------//
      private static void ADMIN_MODE() throws IOException {
          if (System.getProperty("ONLINE_JUDGE") == null) {
              w = new Printer(new FileOutputStream("output.txt"));
              sc = new fs(new FileInputStream("input.txt"));
          }
      }
      //-----------------------------------------------------------------------//
  
      //----------------------------START--------------------------------------//
      public static void main(String[] args)
              throws IOException {
  
          ADMIN_MODE();
  
  //        int t = sc.ni();while(t-->0)
              solve();
  
  
          w.close();
      }
  
      static void solve() throws IOException {
          long n = sc.nl(), m = sc.nl();
          List<obj> li = new ArrayList<>();
          for(int i = 0; i < n; i++) {
              li.add(new obj(i, sc.ns().toCharArray()));
          }
          Comparator<obj> cmp = new Comparator<>() {
              public int compare(obj s1, obj s2) {
                  for(int i = 0; i < m; i++) {
                      if(s1.str[i]==s2.str[i]) continue;
                      if(i%2==0) {
                          return Integer.compare(s1.str[i], s2.str[i]);
                      } else return -1*Integer.compare(s1.str[i], s2.str[i]);
                  }
                  return 0;
              }
          };
          li.sort(cmp);
          for(int i = 0; i < n; i++) {
              w.pr((li.get(i).id+1)+" ");
          }
          w.pl();
      }
  
      static class obj {
          int id;
          char[] str;
  
          public obj(int id, char[] str) {
              this.id = id;
              this.str = str;
          }
      }
  }