program name
    implicit none
    character(4):: s
    logical:: fh, sh

    read'(a)', s

    fh = can_be_month(s(1:2))
    sh = can_be_month(s(3:4))

    if (fh .and. sh) print*, 'AMBIGUOUS'
    if ((.not. fh) .and. sh) print*, 'YYMM'
    if (fh .and. (.not. sh)) print*, 'MMYY'
    if ((.not. fh) .and. (.not. sh)) print*, 'NA'


contains
function can_be_month(str) result(ret)
    character(2):: str
    integer(4):: num
    logical:: ret

    read(str,*) num

    ret = (1 <= num .and. num <= 12)

end function
end program name