Python 代码实现:

while True:
    try:
        string = input()
        k = int(input())
        print(string[:k])
    except:
        break