#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repN(i,n) for(int i = (n); i > 0; --i)
#define rep2(i,s,n) for(int i = s; i < (n); ++i)
#define rep2N(i,e,n) for(int i = e; i < ((e) - (n)); --i)

int num[5];
int N, M;
int c[10];

void Solve()
{
  for (int i = 1; i <= 3; ++i){
      num[i] = c[i];
  }

  int ans = num[1] * 100 + num[2] * 10 + num[3];
  switch(N){
    case 3: if (num[1] == 0) ans = -1; break;
    case 2: if (num[1] != 0) ans = -1;
            else if (num[2] == 0) ans = -1; break;
    case 1: if (num[1] != 0 || num[2] != 0) ans = -1; break;
  }
  cout << ans << endl;
}

void Init()
{
  cin >> N >> M;
  int tmp1, tmp2;
  bool set[5];
  for (int i = 1; i < 3; ++i)
    set[i] = false;

  for (int i = 0; i < M; ++i){
    cin >> tmp1 >> tmp2;
    if (set[tmp1]){
      if (tmp2 < c[tmp1]) c[tmp1] = tmp2;
    } else {
      c[tmp1] = tmp2;
      set[tmp1] = true;
    }
  }
  for (int i = 1; i <= 3; ++i){
    num[i] = 0;
  }
}
void Clean(){}

int main(){ Init(); Solve(); Clean(); return 0; }
