def flip_pancakes(pancakes, flipper):
    """ Calculates the minimum number of flips
    
    :param pancakes: string representing line of pancakes with + (smile) or
                     - (empty)
    :param flipper: the length of a flipper
    :return: number of flips or "IMPOSSIBLE" if it is impossible to do this
    """
    flips = 0
    for i in range(0, len(pancakes) - flipper + 1):
        if pancakes[i] == '-':
            new_pancakes = pancakes[0:i]
            for j in range(0, flipper):
                new_pancakes += '+' if pancakes[i + j] == '-' else '-'
            new_pancakes += pancakes[i + flipper:]
            pancakes = new_pancakes
            flips += 1
    return flips if pancakes == '+' * len(pancakes) else "IMPOSSIBLE"