def get_order(lm):
   """Return the order of a given SRILM LM."""

   order = 0
   for line in open(lm):
      if line.startswith("ngram "):
         try: n = int(line[len("ngram "):].split('=')[0])
         except: n = 0
         if n > order: order = n
      if order and line.startswith("\\"):
         break
   return order