The present invention provides a compound represented by the formula (I):wherein each symbol is as defined in the specification, or a salt thereof. The compound of the present invention has a glucokinase activity, and is useful as a medicament such as an agent for the prophylaxis or treatment of diabetes, obesity and the like, and the like.