The San arises in the Carpathian Mountains near the village of Sianky , at an elevation of 900 metres , exactly on the Polish-Ukrainian border ( ) and on the continental watershed , and forms the border between Poland and Ukraine for approximately its first 50 km .