import re


def is_mismatch_before_n_flank_of_read(md, n):
    """
    Returns True if there is a mismatch before the first n nucleotides
    of a read, or if there is a mismatch before the last n nucleotides
    of a read.

    :param md: string
    :param n: int
    :return is_mismatch: boolean
    """
    is_mismatch = False
    flank_mm_regex = r"^(\d+).*[ACGT](\d+)$"
    flank_mm = re.findall(flank_mm_regex,md)
    if flank_mm:
        flank_mm = flank_mm[0]
        if flank_mm[1]:
            if int(flank_mm[1]) < n:
                is_mismatch = True
        if flank_mm[0]:
            if int(flank_mm[0]) < n:
                is_mismatch = True
    return is_mismatch