order = int(raw_input("Please input the order of square: "))
top_left = int(raw_input("Please input the top left number:"))

while top_left < 1 or top_left > order:
    print "The top left number is invalid."
    top_left = int(raw_input("Please input the top left number:"))

print "The Latin Square is:"

row_count = 1
while row_count <= order:
    for i in range(order):
        if (top_left + i)%order == 0:
            print order,
        else:
            print (top_left+i)%order,
    print
    row_count += 1
    top_left += 1
