#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)

typedef long long i64;
typedef unsigned long long u64;
typedef boost::multiprecision::int128_t i128;
typedef boost::multiprecision::uint256_t u256;
typedef char str255[256];

#define BIG_PRIME 1'000'000'007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF BIG_PRIME

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 j;
  for (int i = 0; i < M; ++i){
    cin >> j;
    cin >> c[j];
  }
  num[1] = num[2] = num[3] = 0;
}

void Clean(){}

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