The six-party agreement was hammered out among the two Koreas , the United States , Japan , Russia and China .