If you Google you would find this useful information about
pgm headers. It says roughly that the pgm files starting with a format identifier aka "magic number" (P1-P7) which telling you the format type and after it some further details which is new line or white space delimited.
Normally the separation of header and data isnt needed. If you want to convert the image you should look for some library.
The link to some C# code in this
Q&A might inspire you to your next steps.