Joachim had a total of 510 local and foreign stamps. After he gave away 2/5 of the local stamps and 4/7 of the foreign stamps, he had 90 more foreign stamps than local stamps left. How many foreign stamps did Joachim have at first?

local stamps: x

foreign stamps: y
so
x + y = 510
3/7y - 3/5x = 90
-(3 * 35)/5 * x + (3 * 35)/7 * y = 90 * 35
-21x + (3 * 35)/7 * y = 90 * 35
-21x + 15y = 90 * 35
-21x + 15y = 3150
x = 510 - y
-21x + 15y = 3150
-21(510 - y) + 15y = 3150
y = 385
x = 510 - 385 = 125
385 foreign stamps