def insertion_sort(m):
    """
    Sorts a list using the insertion sort algorithm.
    m = The unsorted list.
    Examples
        insertion_sort([4,7,6,3,2,5,1])
        # => [1,2,3,4,5,6,7]
    Complexity: O(n^2)
    Returns the sorted list.
    """

    for j in range(1, len(m)):
        key = m[j]
        i = j - 1

        # shift everything greater than 'key' to it's right
        while i >= 0 and m[i] > key:
            m[i + 1] = m[i]
            i = i - 1

        m[i + 1] = key

    return m