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]]]:
    a_np = np.array(a)
    a_shape=a_np.shape
    a_size=a_np.size
    target_shape=(new_shape[0],new_shape[1])

    # 
    if a_size != target_shape[0]*target_shape[1]:
        return -1
    #
    reshape_a = np.reshape(a_np,target_shape)
    reshape_a_list = reshape_a.tolist()
    return reshape_a_list

    pass

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()