Please help me roughly estimate the magnitude of a quake at a distance d (for example 300km) from the epicenter if the magnitude at the epicenter is m (7 at richter scale) is known.
Your question cannot be answered with any accuracy because the result depends mainly on a key unknown parameter: hypocentral depth D.
To show this, let me use the empirical relationship known as the Lillie formula:
$$m = \log(A) - 2.48 + 2.76*log(d)$$
$m$ is the local magnitude (no units).
$A$ is the amplitude of the maximum ground displacement (in micrometers) of the P-wave, measured at 0.8 Hz.
$d$ is your epicentral distance in km for large distances (hundreds of km).
Note that for low values (when approaching the epicenter) the equation does not hold because the log tends to -inf. That's why these empirical formulas are only used for long epicentral distances, not at local scale (and definitely not at the epicenter).
Following your example, if your earthquake is very shallow you would have a huge magnitude difference between your station at distance d and the epicenter, whereas if the hypocenter is 600 km deep, m will be very similar in both places.
So you need to know the depth of the earthquake to derive the magnitude in the epicenter.