(defn input []
  (vector
    (->> (clojure.string/split (read-line) #"\s")
      (map #(Integer/parseInt %)))
    (apply list (read-line))
    (apply list (read-line))))

(defn gcd
  [a b]
  (if (zero? b)
    a
    (recur b, (mod a b))))

(defn lcm
  [a b]
  (/ (* a b) (gcd a b)))

(defn first-inner [X N S L]
  (let [Number (quot L N)]
    (loop [s S i 0]
      (when-not (or (empty? s) (<= L i))
        (do (aset-char X i (first s))
            (recur
              (rest s)
              (+ i Number)))))))

(defn second-inner [X M T L]
  (let [Number (quot L M)]
    (loop [t T i 0]
      (if (or (empty? t) (<= L i))
        true
        (let [v ^char (aget ^"[C" X i)]
          (if-not (or (= v \space) (= v (first t)))
            false
            (recur
              (rest t)
              (+ i Number))))))))


(defn TwoAbbreviation [[[N M] S T]]
  (let [L (int (lcm N M))
        X (char-array (* L 10) \space)]
    L))




(->> (input)
  TwoAbbreviation
  println)