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;
struct TreeItem {
  long long key, prior, sum;
  size_t size;
  shared_ptr<TreeItem> l, r;
  TreeItem(long long key_, long long prior_)
      : key(key_), prior(prior_), sum(key), l(), r(), size(1) {}
};
class DecartTree {
 public:
  void insert(long long key) {
    shared_ptr<TreeItem> it(new TreeItem(key, distribution(generator)));
    insert(root, it);
  }
  void erase(long long key) { erase(root, key); }
  long long prefix_sum(int l) { return prefix_sum(root, l); }
  DecartTree() : root(), generator(), distribution() {}

 private:
  shared_ptr<TreeItem> root;
  uniform_int_distribution<long long> distribution;
  default_random_engine generator;
  void split(shared_ptr<TreeItem> t, long long key, shared_ptr<TreeItem>& l,
             shared_ptr<TreeItem>& r) {
    if (!t)
      l = r = NULL;
    else if (key <= t->key)
      split(t->l, key, l, t->l), r = t;
    else
      split(t->r, key, t->r, r), l = t;
    if (l) {
      update_sum(l);
      update_size(l);
    }
    if (r) {
      update_sum(r);
      update_size(r);
    }
  }
  void merge(shared_ptr<TreeItem>& t, shared_ptr<TreeItem> l,
             shared_ptr<TreeItem> r) {
    if (!l || !r)
      t = l ? l : r;
    else if (l->prior < r->prior)
      merge(l->r, l->r, r), t = l;
    else
      merge(r->l, l, r->l), t = r;
    if (t) {
      update_sum(t);
      update_size(t);
    }
  }
  void update_sum(shared_ptr<TreeItem> t) {
    t->sum = t->key;
    if (t->l) t->sum += t->l->sum;
    if (t->r) t->sum += t->r->sum;
  }
  void update_size(shared_ptr<TreeItem> t) {
    t->size = 1;
    if (t->l) t->size += t->l->size;
    if (t->r) t->size += t->r->size;
  }
  void insert(shared_ptr<TreeItem>& t, shared_ptr<TreeItem> it) {
    if (!t)
      t = it;
    else if (it->prior < t->prior)
      split(t, it->key, it->l, it->r), t = it;
    else
      insert((t->key < it->key) ? t->r : t->l, it);
    if (t) {
      update_sum(t);
      update_size(t);
    }
  }
  void erase(shared_ptr<TreeItem>& t, long long key) {
    if (t->key == key)
      merge(t, t->l, t->r);
    else
      erase((t->key < key) ? t->r : t->l, key);
    if (t) {
      update_sum(t);
      update_size(t);
    }
  }
  long long prefix_sum(shared_ptr<TreeItem> t, int l) {
    if (!t || l == 0) return 0ll;
    if (l == t->size) return t->sum;
    if (t->l && l <= t->l->size) return prefix_sum(t->l, l);
    if (t->l)
      return prefix_sum(t->l, t->l->size) + t->key +
             prefix_sum(t->r, l - 1 - t->l->size);
    return t->key + prefix_sum(t->r, l - 1);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  int n, w;
  cin >> n >> w;
  vector<pair<pair<int, int>, int> > a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first.second >> a[i].first.first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  int start_l = max(0, w - n);
  long long current_result = 0;
  for (int i = 0; i < start_l; ++i) current_result += a[i].first.second;
  long long best_result = -1, best_position = -1;
  DecartTree tree;
  for (int i = 0; i < start_l; ++i)
    tree.insert(a[i].first.first - a[i].first.second);
  for (int i = start_l; i < n; ++i) tree.insert(a[i].first.second);
  for (int j = start_l; j <= min(w, n); ++j) {
    long long current = tree.prefix_sum(w - j);
    if (best_position == -1 || best_result > current_result + current) {
      best_position = j;
      best_result = current_result + current;
    }
    if (j < n) {
      current_result += a[j].first.second;
      tree.erase(a[j].first.second);
      tree.insert(a[j].first.first - a[j].first.second);
    }
  }
  cout << best_result << "\n";
  vector<int> ans(n);
  for (int i = 0; i < best_position; ++i) ans[a[i].second] = 1;
  vector<pair<int, int> > s(n);
  for (int i = 0; i < best_position; ++i)
    s[i] = make_pair(a[i].first.first - a[i].first.second, a[i].second);
  for (int i = best_position; i < n; ++i)
    s[i] = make_pair(a[i].first.second, a[i].second);
  sort(s.begin(), s.end());
  for (int k = 0; k < w - best_position; ++k) ans[s[k].second] += 1;
  for (int i = 0; i < n; ++i) cout << ans[i];
  return 0;
}