Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    if N >= M:
        print(0)
        sys.exit(0)
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)


Fixed submission:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    if N >= M:
        print(0)
        sys.exit(0)
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)


Fixed submission:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    if N >= M:
        print(0)
        sys.exit(0)
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)


Fixed submission:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    if N >= M:
        print(0)
        sys.exit(0)
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)