#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool ckmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool ckmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
const long long MaxN = 3e5 + 50;
long long n, W;
long long opt[MaxN], a[MaxN], b[MaxN];
struct Fraxinus {
  long long C, k1, k2;
  inline long long val(long long x) const { return k1 * a[x] + k2 * b[x]; }
  struct Node {
    long long x, k1, k2;
    Node(long long y, long long d1, long long d2) { x = y, k1 = d1, k2 = d2; }
    Node() { x = k1 = k2 = 0; }
    inline long long val(long long x) const { return k1 * a[x] + k2 * b[x]; }
    inline bool operator<(const Node &nt) const { return val(nt.x) < val(x); }
  };
  std::priority_queue<Node> Q;
  inline void work() {
    while (!Q.empty() && opt[Q.top().x] != C) Q.pop();
  }
  inline void push(long long x) { Q.push(Node(x, k1, k2)); }
  inline long long ok() {
    work();
    return !Q.empty();
  }
  inline long long top() {
    work();
    return Q.top().x;
  }
  inline long long vtp() {
    work();
    return val(Q.top().x);
  }
} q[6];
inline void to0(long long x) { opt[x] = 0, q[1].push(x), q[4].push(x); }
inline void to1(long long x) { opt[x] = 1, q[2].push(x), q[3].push(x); }
inline void to2(long long x) { opt[x] = 2, q[5].push(x); }
signed main(void) {
  read(n, W);
  q[2].C = q[3].C = 1, q[5].C = 2;
  q[1].k1 = 1, q[2].k1 = -1, q[2].k2 = 1, q[3].k1 = -1, q[4].k2 = 1,
  q[5].k1 = 1, q[5].k2 = -1;
  for (long long i = 1; i <= n; ++i) read(a[i], b[i]);
  for (long long i = 1; i <= n; ++i) to0(i);
  register long long ans = 0;
  while (W--) {
    register long long cur = 0, mx = 1e18;
    if (q[1].ok() && ckmin(mx, q[1].vtp())) cur = 1;
    if (q[2].ok() && ckmin(mx, q[2].vtp())) cur = 2;
    if (q[3].ok() && q[4].ok() && ckmin(mx, q[3].vtp() + q[4].vtp())) cur = 3;
    if (q[4].ok() && q[5].ok() && ckmin(mx, q[4].vtp() + q[5].vtp())) cur = 4;
    ans += mx;
    if (cur == 1)
      to1(q[1].top());
    else if (cur == 2)
      to2(q[2].top());
    else if (cur == 3)
      to2(q[4].top()), to0(q[3].top());
    else
      to1(q[5].top()), to2(q[4].top());
  }
  write(ans), std::puts("");
  for (long long i = 1; i <= n; ++i) write(opt[i]);
  std::puts("");
  return 0;
}
