Create a dynamic tunnel (socks5 proxy) from m1 to m2, using port 8888
$ ssh myuser@m2 -fN -D 8888
Set apt to use the socks proxy created above
$ echo "Acquire::http::proxy "socks5h://localhost:8888";" | sudo tee -a /etc/apt/apt.conf.d/12proxy
Run apt command as usual in m1, and your apt command will be tunneled via the socks5h proxy
$ sudo apt update
...
0% [Connecting to SOCKS5h proxy (socks5h://localhost:8888)] [Connecting to SOCKS5h proxy (socks5h://localhost:8888)]
...
Once you are done, do not forget to kill the tunnel
$ kill `pidof ssh`
$ sudo sed -i 's/Acquire/#Acquire/' /etc/apt/apt.conf.d/12proxy