#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60; 

int main()
{
  //入力
  int M, N; cin >> M >> N;
  vector<pair<int,int>> p(M+1);
  rep(i,M) cin >> p[i].first >> p[i].second;
  bool check = false;
  int ans[M] = {0}; 
  sort(p.begin(), p.end());
  
  /*ダメな条件*/
  //1桁目がゼロ
  rep(i,M) {
    if(p[i].first == 1 && p[i].second == 0)
      check = true;
  }
  //同じ桁を違う数字で規定
  rep(i,M-1)
  {
    if(p[i].first == p[i+1].first  && p[i].second != p[i+1].second)
      check = true;
  }
  
  /*良い時*/
  //数字作成
  if(!check)
  {
    rep(i,M-1)
    {
      if(p[i].first != p[i+1].first)
      {
        if(p[i].first == 1) ans[0] += p[i].second;
        if(p[i].first == 2) ans[1] += p[i].second;
        if(p[i].first == 3) ans[2] += p[i].second;
      }
    }
  }

  //出力
  if(check) cout << "-1" << endl;
  else rep(i,N) cout << ans[i];
}