#include <bits/stdc++.h>
using namespace std;
const int MAXN = 700000;
pair<int, pair<int, int> > s[MAXN * 2];
int ns = 0;
int a[MAXN], b[MAXN];
int c[MAXN];
int main() {
  int n, w;
  scanf("%d%d", &n, &w);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    c[i] = 0;
    if (b[i] > a[i] * 2) {
      s[ns++] = pair<int, pair<int, int> >(2 * a[i], pair<int, int>(i, 1));
      s[ns++] =
          pair<int, pair<int, int> >(2 * (b[i] - a[i]), pair<int, int>(i, 1));
    } else
      s[ns++] = pair<int, pair<int, int> >(b[i], pair<int, int>(i, 2));
  }
  sort(s, s + ns);
  int count = 0;
  for (int i = 0; count < w && (count + s[i].second.second <= w); i++) {
    c[s[i].second.first] += s[i].second.second;
    count += s[i].second.second;
  }
  if (count < w) {
    int best = -1, bcost;
    for (int i = 0; i < n; i++) {
      if (c[i] == 0 && (best < 0 || bcost > a[i])) best = i, bcost = a[i];
      if (c[i] == 1 && (best < 0 || bcost > b[i] - a[i]))
        best = i, bcost = b[i] - a[i];
    }
    int big1 = -1, cb1 = 0;
    int big2 = -1, cb2 = 0;
    int sm2 = -1;
    for (int i = 0; i < n; i++) {
      if (c[i] == 1 && (big1 < 0 || a[big1] < a[i])) big1 = i, cb1 = a[i];
      if (c[i] == 2 && (big2 < 0 || b[big2] - a[big2] < b[i] - a[i]))
        big2 = i, cb2 = b[i] - a[i];
      if (c[i] == 0 && (sm2 < 0 || b[sm2] > b[i])) sm2 = i;
    }
    if (big1 < 0 || (big2 >= 0 && cb2 > cb1)) big1 = big2, cb1 = cb2;
    if (big1 >= 0 && sm2 >= 0 && bcost > b[sm2] - cb1) {
      c[big1]--;
      c[sm2] = 2;
    } else
      c[best]++;
  }
  long long sum = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] == 1) sum += a[i];
    if (c[i] == 2) sum += b[i];
    cnt += c[i];
  }
  if (cnt < w)
    while (true)
      ;
  printf("%I64d\n", sum);
  for (int i = 0; i < n; i++) printf("%d", c[i]);
  return 0;
}
