using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("ARC101.C.Test")]

namespace ARC101.C
{
    using Common;
    
    class Program : SolverBase<Input, Unit, Output, int>
    {
        static void Main(string[] args)
        {
            new Program().Run(Console.In, Console.Out);
        }

        public override void Solve(Input input, Output output, IContext context)
        {
            if (input.K == 0)
            {
                output.OutputItem(0);
            }
            else if (input.Xs.First() > 0)
            {
                output.OutputItem(input.Xs[input.K - 1]);
            }
            else if (input.Xs.Last() < 0)
            {
                output.OutputItem(-input.Xs[input.Xs.Length - input.K]);
            }
            else
            {
                var zeroIndex = ~Array.BinarySearch(input.Xs, 0);
                var minDistance = int.MaxValue;

                for (var n = 0; n <= input.K; n++)
                {
                    var p = input.K - n;
                    var pIndex = zeroIndex + p - 2;
                    var nIndex = zeroIndex - n - 1;

                    if (pIndex >= input.Xs.Length || nIndex < 0)
                    {
                        continue;
                    }

                    var pValue = input.Xs[pIndex];
                    var nValue = -input.Xs[nIndex];

                    var distance = Math.Min(pValue, nValue) * 2 + Math.Max(pValue, nValue);

                    minDistance = Math.Min(minDistance, distance);
                }

                output.OutputItem(minDistance);
            }
        }
    }

    class Input : InputBase<Input, Unit>
    {
        public int N { get; private set; }
        public int K { get; private set; }

        public int[] Xs { get; private set; }

        protected override Unit PerseItem(string line, IContext context)
        {
            throw new NotImplementedException();
        }

        protected override int ReadHeaders(TextReader reader, IContext context)
        {
            var parts = reader.ReadLine().Split(' ').Select(int.Parse).ToArray();

            N = parts[0];
            K = parts[1];
            var xs = reader.ReadLine().Split(' ').Select(int.Parse).ToList();

            var index = xs.BinarySearch(0);

            if (index >= 0)
            {
                xs.RemoveAt(index);
                K--;
            }

            Xs = xs.ToArray();

            return 0;
        }
    }

    class Output : OutputBase<Output, int>
    {

    }

    namespace Common
    {
        struct Unit { }

        interface IContext : IDisposable
        {
            T Do<T>(Func<IContext, T> action, string description = null);
            void Do(Action<IContext> action, string description = null);
        }

        class ThinContext : IContext
        {
            public static readonly ThinContext Instance = new ThinContext();

            public void Dispose()
            {

            }

            public T Do<T>(Func<IContext, T> action, string description = null)
            {
                return action(this);
            }

            public void Do(Action<IContext> action, string description = null)
            {
                action(this);
            }
        }

        interface ISolver<TInput, TOutput>
        {
            // ##SKIP-SLIM
            void Run(TextReader inputReader, TextWriter outputWriter, IContext context = null);
        }

        abstract class SolverBase<TInput, TInputItem, TOutput, TOutputItem> : ISolver<TInput, TOutput>
            where TInput : IInput<TInput, TInputItem>, new()
            where TOutput : IOutput<TOutput, TOutputItem>, new()
        {
            public abstract void Solve(TInput input, TOutput output, IContext context);

            public void Run(TextReader inputReader, TextWriter outputWriter, IContext context = null)
            {
                context = context ?? ThinContext.Instance;

                using (var input = context.Do(innerContext => new TInput().Initialize(inputReader, innerContext)))
                using (var output = context.Do(innerContext => new TOutput().Initialize(outputWriter, innerContext)))
                {
                    context.Do(innerContext => Solve(input, output, innerContext), "solving");
                }
            }
        }

        interface IInput<TSelf, TInputItem> : IEnumerable<TInputItem>, IDisposable
                where TSelf : IInput<TSelf, TInputItem>
        {
            TSelf Initialize(TextReader reader, IContext context);
        }

        interface IOutput<TSelf, TOutputItem> : IDisposable
            where TSelf : IOutput<TSelf, TOutputItem>
        {
            TSelf Initialize(TextWriter writer, IContext context);
        }

        abstract class InputBase<TSelf, TInputItem> : IInput<TSelf, TInputItem>
                where TSelf : class, IInput<TSelf, TInputItem>
        {
            protected TextReader Reader { get; private set; }
            public IContext Context { get; private set; }
            protected int TotalItemCount { get; private set; }

            public virtual TSelf Initialize(TextReader reader, IContext context)
            {
                Reader = reader;
                Context = context;

                TotalItemCount = ReadHeaders(reader, context);

                return this as TSelf;
            }

            protected abstract int ReadHeaders(TextReader reader, IContext context);
            protected virtual TInputItem ReadItem(TextReader reader, IContext context)
            {
                return PerseItem(reader.ReadLine(), context);
            }

            protected abstract TInputItem PerseItem(string line, IContext context);

            public virtual void Dispose()
            {
                if (Context != null)
                {
                    Context.Dispose();
                    Context = null;
                }

                Reader = null;
            }

            public virtual IEnumerator<TInputItem> GetEnumerator()
            {
                for (var i = 0; i < TotalItemCount; i++)
                {
                    yield return ReadItem(Reader, Context);
                }
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
        }

        abstract class OutputBase<TSelf, TOutputItem> : IOutput<TSelf, TOutputItem>
                where TSelf : class, IOutput<TSelf, TOutputItem>
        {
            protected TextWriter Writer { get; private set; }
            public IContext Context { get; private set; }

            public virtual TSelf Initialize(TextWriter writer, IContext context)
            {
                Writer = writer;
                Context = context;

                return this as TSelf;
            }

            public virtual void OutputItem(TOutputItem item)
            {
                OutputItem(item, Writer, Context);
            }

            protected virtual void OutputItem(TOutputItem item, TextWriter writer, IContext context)
            {
                writer.WriteLine(item);
            }

            public virtual void Dispose()
            {
                if (Context != null)
                {
                    Context.Dispose();
                    Context = null;
                }

                Writer = null;
            }
        }
    }
}

Measured memory_bytes: 21856