def coeff(f, m):
  """
  Returns coefficient of monomial m in f.
  Works with univariate polynomials and multivariate
  Singular polynomials.
  """
  try:
    return f.monomial_coefficient(m)
  except AttributeError:
    return f.coeff(m)