Optimal Network Compression