Garbage using serial functions in Arduino Due

Here is a sketch with a counter. Looks like Serial has several, maybe 6, bytes of garbage input when a reset from opening a Serial monitor happens.

Load this sketch into the Due:

int n = 0;
void setup() {
  Serial.begin(115200);
}
void loop() {
  if (Serial.available()) {
    Serial.read();
    Serial.write('N');
    Serial.println(++n);
  }
}

then open a serial monitor and you get this:

þþN5
N6

Close and open the serial monitor again and you get a similar result. Almost always ending with the "N6" line.

Adding a delay(2000) after Serial.begin seems to fix it after reload but not on a reopen of the monitor.

I tried this but still get the problem.

while (!Serial);

So if you write for Uno, Leonardo, and Due what is the correct answer to avoid this?