#include <cstdio>
#include <iostream>
using namespace std;
int s[10], c[10];
bool check1(int x)
{
  for(int i = 1; i <= M; i++)
  {
    if(c[i] != x)
      return false;
  }
  return true;
}

bool check2(int x)
{
  int d[3];
  d[1] = x / 10;
  d[2] = x % 10;
  for(int i = 1; i <= M; i++)
  {
    if(d[s[i]] != c[i])
      return false;
  }
  return true;
}

bool check3(int x)
{
  int d[4];
  d[1] = x / 100;
  d[2] = x / 10 % 10;
  d[3] = x % 10;
  for(int i = 1; i <= M; i++)
  {
    if(d[s[i]] != c[i])
      return false;
  }
  return true;
}

int main()
{
  int N, M, i, ans;
  cin >> N >> M;
  for(i = 1; i <= M; i++)
  {
    cin >> s[i] >> c[i];
  }
  if(N==1)
  {
    for(ans = 0; ans <= 9; ans++)
    {
      if(check1(ans))
      {
        cout << ans;
        return 0;
      }
    }
    cout << -1;
    return 0;
  }
  else if(N == 2)
  {
    for(ans = 10; ans <= 99; ans++)
    {
      if(check2(ans))
      {
        cout << ans;
        return 0;
      }
    }
    cout << -1;
    return 0;
  }
  else
  {
    for(ans = 100; ans <= 999; ans++)
    {
      if(check3(ans))
      {
        cout << ans;
        return 0;
      }
    }
    cout << -1;
    return 0;
  }
  return 0;
}