function findFirstUnqiueNChars(buffer, n) {
for (let i = n; i < buffer.length; i++) {
const start = i - n;
const substring = buffer.slice(start, i);
const charCount = new Map();
let foundDuplicate = false;
for (let j = 0; j < substring.length; j++) {
if (charCount.get(substring[j])) foundDuplicate = true;
else charCount.set(substring[j], true);
}
if (!foundDuplicate) return i;
}
return -1;
}