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>
using namespace std;
const int maxn = 300010;
int n, w, a[maxn], b[maxn];
set<pair<int, int> > s0to1, s1to2, s2to1, s1to0, s0to2;
int main() {
  scanf("%d %d", &n, &w);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%d %d", &a[i], &b[i]);
    s0to1.insert(pair<int, int>(a[i], i));
    s0to2.insert(pair<int, int>(b[i], i));
  }
  long long ans = 0;
  while (w--) {
    int best = int(1e9 + 7);
    int bd = -1;
    if (!s0to1.empty() && s0to1.begin()->first < best) {
      best = s0to1.begin()->first;
      bd = 0;
    }
    if (!s1to2.empty() && s1to2.begin()->first < best) {
      best = s1to2.begin()->first;
      bd = 1;
    }
    if (!s0to2.empty()) {
      int cur = s0to2.begin()->first;
      int cwin = 0;
      int td = -1;
      if (!s2to1.empty() && s2to1.rbegin()->first > cwin) {
        td = 1;
        cwin = s2to1.rbegin()->first;
      }
      if (!s1to0.empty() && s1to0.rbegin()->first > cwin) {
        td = 0;
        cwin = s1to0.rbegin()->first;
      }
      if (cur - cwin < best) {
        best = cur - cwin;
        bd = 2 + td;
      }
    }
    if (bd == 0) {
      int i = s0to1.begin()->second;
      ans += a[i];
      s0to1.erase(s0to1.begin());
      s0to2.erase(pair<int, int>(b[i], i));
      s1to2.insert(pair<int, int>(b[i] - a[i], i));
      s1to0.insert(pair<int, int>(a[i], i));
      int cd = -1;
      int cb = 0;
      if (!s2to1.empty() && s2to1.rbegin()->first > cb) {
        cb = s2to1.rbegin()->first;
        cd = 0;
      }
      if (!s1to0.empty() && s1to0.rbegin()->first > cb &&
          s1to0.rbegin()->second != s1to2.begin()->second) {
        cb = s1to0.rbegin()->first;
        cd = 1;
      }
      if (s1to0.size() > 1) {
        set<pair<int, int> >::iterator it = s1to0.end();
        it--;
        it--;
        if (it->first > cb && it->second != s1to2.begin()->second) {
          cb = it->first;
          cd = 2;
        }
      }
      if (cb > s1to2.begin()->first) {
        if (cd == 0) {
          ans += s1to2.begin()->first - s2to1.rbegin()->first;
          int i12 = s1to2.begin()->second;
          int i21 = s2to1.rbegin()->second;
          s1to2.erase(s1to2.begin());
          s1to0.erase(pair<int, int>(a[i12], i12));
          s2to1.erase(--s2to1.end());
          s1to2.insert(pair<int, int>(b[i21] - a[i21], i21));
          s1to0.insert(pair<int, int>(a[i21], i21));
          s2to1.insert(pair<int, int>(b[i12] - a[i12], i12));
        } else if (cd == 1) {
          ans += s1to2.begin()->first - s1to0.rbegin()->first;
          int i12 = s1to2.begin()->second;
          int i10 = s1to0.rbegin()->second;
          s1to2.erase(pair<int, int>(a[i12], i12));
          s1to0.erase(pair<int, int>(a[i10], i10));
          s2to1.insert(pair<int, int>(b[i12] - a[i12], i12));
          s0to1.insert(pair<int, int>(a[i10], i10));
          s0to2.insert(pair<int, int>(b[i10], i10));
        } else if (cd == 2) {
          set<pair<int, int> >::iterator it = s1to0.end();
          it--;
          it--;
          ans += s1to2.begin()->first - it->first;
          int i12 = s1to2.begin()->second;
          int i10 = it->second;
          s1to2.erase(pair<int, int>(a[i12], i12));
          s1to0.erase(pair<int, int>(a[i10], i10));
          s2to1.insert(pair<int, int>(b[i12] - a[i12], i12));
          s0to1.insert(pair<int, int>(a[i10], i10));
          s0to2.insert(pair<int, int>(b[i10], i10));
        }
      }
    } else if (bd == 1) {
      int i = s1to2.begin()->second;
      ans += b[i] - a[i];
      s1to2.erase(s1to2.begin());
      s1to0.erase(pair<int, int>(a[i], i));
      s2to1.insert(pair<int, int>(b[i] - a[i], i));
    } else if (bd == 2) {
      int i02 = s0to2.begin()->second;
      int i10 = s1to0.rbegin()->second;
      ans += s0to2.begin()->first - s1to0.rbegin()->first;
      s0to2.erase(pair<int, int>(b[i02], i02));
      s0to1.erase(pair<int, int>(a[i02], i02));
      s1to0.erase(pair<int, int>(a[i10], i10));
      s1to2.erase(pair<int, int>(b[i10] - a[i10], i10));
      s2to1.insert(pair<int, int>(b[i02] - a[i02], i02));
      s0to1.insert(pair<int, int>(a[i10], i10));
      s0to2.insert(pair<int, int>(b[i10], i10));
    } else if (bd == 3) {
      int i02 = s0to2.begin()->second;
      int i21 = s2to1.rbegin()->second;
      ans += s0to2.begin()->first - s2to1.rbegin()->first;
      s0to2.erase(pair<int, int>(b[i02], i02));
      s0to1.erase(pair<int, int>(a[i02], i02));
      s2to1.erase(pair<int, int>(b[i21] - a[i21], i21));
      s2to1.insert(pair<int, int>(b[i02] - a[i02], i02));
      s1to2.insert(pair<int, int>(b[i21] - a[i21], i21));
      s1to0.insert(pair<int, int>(a[i21], i21));
    }
  }
  cout << ans << endl;
  for (int i = 0; i < (int)(n); i++) {
    if (s1to0.find(pair<int, int>(a[i], i)) != s1to0.end() ||
        s1to2.find(pair<int, int>(b[i] - a[i], i)) != s1to2.end())
      printf("1");
    else if (s2to1.find(pair<int, int>(b[i] - a[i], i)) != s2to1.end())
      printf("2");
    else
      printf("0");
  }
  printf("\n");
  return 0;
}