Problem: Everyone who has played Cut the Rope knows full well how the gameplay is organized. All levels in the game are divided into boxes. Initially only one box with some levels is available. Player should complete levels to earn stars, collecting stars opens new box with levels.

<image>

Imagine that you are playing Cut the Rope for the first time. Currently you have only the levels of the first box (by the way, it is called "Cardboard Box"). Each level is characterized by two integers: ai — how long it takes to complete the level for one star, bi — how long it takes to complete the level for two stars (ai < bi).

You want to open the next box as quickly as possible. So, you need to earn at least w stars. How do make it happen? Note that the level can be passed only once: either for one star or for two. You do not necessarily need to pass all the levels.

Input

The first line contains two integers n and w (1 ≤ n ≤ 3·105; 1 ≤ w ≤ 2n) — the number of levels in the first box and the number of stars you need to open another box. Each of the following n lines contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the attributes of the i-th level.

Output

In the first line print integer t — the minimum time you need to open the next box. 

In the next line, print n digits without spaces — the description of the optimal scenario: 

  * if you need to pass the i-th level for one star, the i-th digit should equal 1; 
  * if you need to pass the i-th level for two stars, the i-th digit should equal 2; 
  * if you do not need to pass the i-th level at all, the i-th digit should equal 0. 

Examples

Input

2 3
1 2
1 2


Output

3
12


Input

5 3
10 20
5 10
10 20
6 9
25 30


Output

14
01020

Note

In the first test sample, answer 21 is also assumed correct.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
FILE *_stderr = freopen("nul", "w", stderr);
using std::pair;
using std::vector;
template <class T>
inline vector<T> &operator<<(vector<T> &x, const T &y) {
  x.push_back(y);
  return x;
}
using std::map;
using std::set;
template <class T>
inline set<T> &operator<<(set<T> &x, const T &y) {
  x.insert(y);
  return x;
}
using std::list;
template <class T>
inline list<T> &operator<<(list<T> &x, const T &y) {
  x.push_back(y);
  return x;
}
template <class T>
inline list<T> &operator>>(list<T> &x, const T &y) {
  x.push_front(y);
  return x;
}
inline void read(int &x) {
  char c = getchar();
  while (c < '0') c = getchar();
  x = 0;
  while (c >= '0') x = (x << 3) + (x << 1) + c - '0', c = getchar();
}
inline void read(long long &x) {
  char c = getchar();
  while (c < '0') c = getchar();
  x = 0;
  while (c >= '0') x = (x << 3) + (x << 1) + c - '0', c = getchar();
}
inline void read(double &x) { scanf("%lf", &x); }
inline void read(long double &x) {
  double tmp;
  scanf("%lf", &tmp);
  x = tmp;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 1000000000)
    goto x9;
  else if (x >= 100000000)
    goto x8;
  else if (x >= 10000000)
    goto x7;
  else if (x >= 1000000)
    goto x6;
  else if (x >= 100000)
    goto x5;
  else if (x >= 10000)
    goto x4;
  else if (x >= 1000)
    goto x3;
  else if (x >= 100)
    goto x2;
  else if (x >= 10)
    goto x1;
  else
    goto x0;
x9:
  putchar(x / 1000000000 + '0');
  x %= 1000000000;
x8:
  putchar(x / 100000000 + '0');
  x %= 100000000;
x7:
  putchar(x / 10000000 + '0');
  x %= 10000000;
x6:
  putchar(x / 1000000 + '0');
  x %= 1000000;
x5:
  putchar(x / 100000 + '0');
  x %= 100000;
x4:
  putchar(x / 10000 + '0');
  x %= 10000;
x3:
  putchar(x / 1000 + '0');
  x %= 1000;
x2:
  putchar(x / 100 + '0');
  x %= 100;
x1:
  putchar(x / 10 + '0');
  x %= 10;
x0:
  putchar(x + '0');
}
inline void write(const long long x) { printf("%I64d", x); }
template <class T>
inline T min(const T x, const T y) {
  if (x < y)
    return x;
  else
    return y;
}
template <class T>
inline T &min2(const T &x, const T &y) {
  if (x < y)
    return x;
  else
    return y;
}
template <class T>
inline T max(const T x, const T y) {
  if (x > y)
    return x;
  else
    return y;
}
template <class T>
inline T &max2(const T &x, const T &y) {
  if (x > y)
    return x;
  else
    return y;
}
template <class T>
inline T sqr(const T x) {
  return x * x;
}
template <class T>
inline T sqr2(const T &x) {
  return x * x;
}
int n, w;
int first[300086], second[300086], lv[300086];
struct s {
  int c, x, y;
};
inline bool operator<(const s &first, const s &second) {
  if (first.c != second.c) return first.c < second.c;
  if (first.x != second.x) return first.x < second.x;
  return first.y < second.y;
}
std::set
 S;
int main() {
  read(n);
  read(w);
  for (int i = (1); i <= (n); ++i) {
    read(first[i]), read(second[i]);
    second[i] -= first[i];
    if (first[i] >= second[i]) {
      S << (s){first[i] + second[i], i, 2};
    } else {
      S << (s){first[i] + first[i], i, 1};
      S << (s){second[i] + second[i], i, 1};
    }
  }
  memset(lv, 0, sizeof(lv));
  int ma2 = -1, ma2i = -1;
  int cw = 0;
  long long tans = 0;
  while (cw < w) {
    int cc = S.begin()->c;
    std::set
::iterator til = S.lower_bound((s){cc, 400000, 400000});
    int ccw = 0;
    for (std::set
::iterator i = S.begin(); i != til; ++i) ccw += i->y;
    if (cw + ccw <= w) {
      cw += ccw;
      for (std::set
::iterator i = S.begin(); i != til; ++i) {
        lv[i->x] += i->y;
        tans += (long long)cc * (long long)i->y / 2LL;
        if (i->y == 2) {
          int ca2 = second[i->x];
          if (ca2 > ma2) ma2 = ca2, ma2i = i->x;
        } else {
          int ca2 = i->c / 2LL;
          if (ca2 > ma2) ma2 = ca2, ma2i = i->x;
        }
      }
      S.erase(S.begin(), til);
    } else if ((w - cw) % 2) {
      bool succ = false;
      for (std::set
::iterator i = S.begin(); i != til; ++i)
        if (i->y == 1) {
          succ = true;
          break;
        }
      if (succ) {
        if (cw + 1 < w)
          for (std::set
::iterator i = S.begin(); i != til; ++i)
            if (i->y == 2) {
              lv[i->x] += i->y;
              tans += (long long)cc * (long long)i->y / 2LL;
              cw += i->y;
              if (cw + 1 == w) break;
            }
        if (cw < w)
          for (std::set
::iterator i = S.begin(); i != til; ++i)
            if (i->y == 1) {
              lv[i->x] += i->y;
              tans += (long long)cc * (long long)i->y / 2LL;
              cw += i->y;
              if (cw == w) break;
            }
      } else {
        int mm = 1000000009, mi;
        for (int i = (1); i <= (n); ++i) {
          if (lv[i] == 0 && first[i] < mm) mm = first[i], mi = i;
          if (lv[i] == 1 && second[i] < mm) mm = second[i], mi = i;
        }
        if (mm < cc - ma2) {
          ++lv[mi];
          tans += (long long)mm;
          ++cw;
          if (cw < w)
            for (std::set
::iterator i = S.begin(); i != til; ++i)
              if (i->x != mi) {
                lv[i->x] += i->y;
                tans += (long long)cc * (long long)i->y / 2LL;
                cw += i->y;
                if (cw == w) break;
              }
        } else {
          --lv[ma2i];
          tans -= (long long)ma2;
          --cw;
          if (cw < w)
            for (std::set
::iterator i = S.begin(); i != til; ++i) {
              lv[i->x] += i->y;
              tans += (long long)cc * (long long)i->y / 2LL;
              cw += i->y;
              if (cw == w) break;
            }
        }
      }
    } else {
      for (std::set
::iterator i = S.begin(); i != til; ++i)
        if (i->y == 2) {
          lv[i->x] += i->y;
          tans += (long long)cc * (long long)i->y / 2LL;
          cw += i->y;
          if (cw == w) break;
        }
      if (cw < w) {
        for (std::set
::iterator i = S.begin(); i != til; ++i)
          if (i->y == 1) {
            lv[i->x] += i->y;
            tans += (long long)cc * (long long)i->y / 2LL;
            cw += i->y;
            if (cw == w) break;
          }
      }
    }
  }
  printf("%I64d\n", tans);
  for (int i = (1); i <= (n); ++i) printf("%d", lv[i]);
  return 0;
}