def kmp(m_str, s_str) -> int:
    """
    The string matching algorithms
    :param m_str: main string
    :param s_str: pattern string
    :return: matching location or -1 if there is no matching
    """
    next_ls = [-1] * len(s_str)
    m = 1
    s = 0

    next_ls[0] = -1
    while m < len(s_str) - 1:
        if s_str[m] == s_str[s] or s == -1:
            m += 1
            s += 1
            next_ls[m] = s
        else:
            s = next_ls[s]

    i = j = 0
    while i < len(m_str) and j < len(s_str):
        if m_str[i] == s_str[j] or j == -1:
            i += 1
            j += 1
        else:
            j = next_ls[j]

    if j == len(s_str):
        return i - j
    return -1