#include namespace nono { void solve() { int n, m; std::cin >> n >> m; std::vector a(m); for (int i = 0; i < m; i++) std::cin >> a[i]; for (int i = 0; i < m; i++) a[i]--; constexpr int INF = 1e9; std::vector dp(m + 1, std::vector(n, INF)); for (int i = 0; i < n; i++) { dp[0][i] = i; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int cur = (a[m - i - 1] == j ? j + 1 : (a[m - i - 1] + 1 == j ? j - 1 : j)); for (int k = 0; k < n; k++) { dp[i + 1][k] = std::min(dp[i + 1][k], dp[i][j] + std::abs(k - cur)); } } } for (int i = 1; i < n; i++) { std::cout << dp[m][i] << (i + 1 == n ? '\n' : ' '); } } } // namespace nono int main() { std::cin.tie(0)->sync_with_stdio(0); std::cout << std::fixed << std::setprecision(16); int t = 1; while (t--) nono::solve(); }