Electronic structure of titanium and niobium carbides with beryllium impurity