{$X+}

type
  THistory = array [0..40000] of Char;
  PHistory = ^THistory;

const
  maxD = 13;

var
  f: Text;
  p: array [1..maxD] of PHistory;
  s: String;

function R(p: PHistory; a: String): Char;
var
  i, n: Integer;
begin
  n := 0;
  for i := 1 to Length(a) do
    n := (n shl 1) + ord(a[i]) - ord('0');
  R := p^[n-1];
end;

procedure D(p: PHistory; a: String; v: Char);
var
  i, n: Integer;
begin
  n := 0;
  for i := 1 to Length(a) do
    n := (n shl 1) + ord(a[i]) - ord('0');
  p^[n-1] := v;
end;

procedure ToHistory(ch: Char);
var
  i: Integer;
begin
  for i := 1 to Length(s) do
    D(p[i], Copy(s, 1, i), ch);
  s := ch + Copy(s, 1, maxD - 1);
end;

function Forecast: Char;
var
  i: Integer;
  ch: Char;
begin
  for i := Length(s) downto 1 do begin
    ch := R(p[i], Copy(s, 1, i));
    Forecast := ch;
    if ch <> '?' then begin {writeln(i);} exit; end;
  end;
  Forecast := '0';
end;

var
  i, n, L: Longint;
  ch: Char;

begin
  n := 1;
  for i := 1 to maxD do begin
    n := n shl 1;
    GetMem(p[i], n);
    FillChar(p[i]^, n, '?');
  end;
  Readln(n, L);
  s := '';
  for i := 1 to n do begin
    Read(ch);
    ToHistory(ch);
  end;
  for i := 1 to L do begin
    ch := Forecast;
    Write(ch);
    ToHistory(ch);
  end;
end.
