You can't. Apple stopped supporting that feature many years ago and with a M1 Mac and Big Sur you will be lucky to get it to work, even if you had a supported iMac (which you don't).
Use your iMac as a display with Target Display Mode - Apple Support - https://support.apple.com/HT204592 - iMacs late 2009-Mid 2014. This document is "archived" which means this feature is no longer supported by Apple for recents Macs and operating system versions.
This could only be done with a very few and very specific older iMacs and support was very limited. Read this topic for a 2021 perspective on this: https://discussions.apple.com/thread/252271436?answerId=254300142022#254300142022
and this 2021 post by Allan Jones about software limitations:
https://discussions.apple.com/thread/252344497?answerId=254428494022#254428494022