#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000;
struct Good {
  int a, b, s, id;
} g[maxn << 2];
int n, w, tot, ans[maxn], x[maxn], y[maxn];
long long t;
Good MK(int a, int b, int s, int id) {
  Good tmp;
  tmp.a = a;
  tmp.b = b;
  tmp.s = s;
  tmp.id = id;
  return tmp;
}
bool cmp(Good x, Good y) { return 1LL * x.b * y.s < 1LL * y.b * x.s; }
bool Check(int cm) {
  int m = -1, f = -1, d;
  for (int i = 0; i < n; i++) {
    if (ans[i] == 2 && (m < 0 || y[i] - x[i] > d)) {
      m = i;
      d = y[i] - x[i];
    }
    if (ans[i] == 1 && (m < 0 || x[i] > d)) {
      m = i;
      d = x[i];
    }
    if (ans[i] == 0 && (f < 0 || y[i] < y[f])) f = i;
  }
  if (m >= 0 && f >= 0 && y[f] - d < cm) {
    ans[f] = 2;
    ans[m]--;
    t += y[f] - d;
    return 0;
  }
  return 1;
}
int main() {
  tot = 0;
  scanf("%d%d", &n, &w);
  int a, b;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    x[i] = a, y[i] = b;
    if (b - a >= a) {
      g[tot++] = MK(a, a, 1, i);
      g[tot++] = MK(b - a, b - a, 1, i);
    } else {
      g[tot++] = MK(a, b, 2, i);
    }
  }
  sort(g, g + tot, cmp);
  int i;
  for (i = 0; i < tot && w >= g[i].s; i++) {
    ans[g[i].id] += g[i].s;
    t += g[i].b;
    w -= g[i].s;
  }
  if (w == 1) {
    int min = i;
    for (i++; i < tot; i++)
      if (g[i].a < g[min].a) min = i;
    if (Check(g[min].a)) {
      ans[g[min].id]++;
      t += g[min].a;
    }
  }
  cout << t << endl;
  for (int i = 0; i < n; i++) printf("%d", ans[i]);
  cout << endl;
}
