from typing import List, Tuple, Union
import numpy as np
def reshape_matrix(a: List[List[Union[int, float]]], new_shape: Tuple[int, int]) -> List[List[Union[int, float]]]:
n=new_shape[0]
m=new_shape[1]
if n*m != len(a)*len(a[0]):
return -1
ls = [j for i in a for j in i]
res = [[0]*m for _ in range(n)]
for i in range(n):
for j in range(m):
res[i][j] = ls.pop(0)
return res
def main():
try:
a = eval(input())
new_shape = eval(input())
result = reshape_matrix(a, new_shape)
print(result)
except Exception as e:
print(f"输入格式错误: {e}")
if __name__ == "__main__":
main()