#include <bits/stdc++.h>
using namespace std;
static const double pi = 3.141592653589793;
int main() {
  int a, b;
  cin >> a >> b;
  int dp[b];
  int gh[b];
  for (int i = 0; i < b; i++) {
    int x, y;
    cin >> x >> y;
    dp[i] = x;
    gh[i] = y;
  }
  int z = 0;
  for (int i = 0; i < b; i++) {
    for (int j = 0; j < b; j++) {
      if (dp[i] == dp[j] & gh[i] != gh[j]) {
        z = 1;
      }
    }
  }
  if (z == 1)
    cout << -1;
  else {
    int t = 0;
    vector<int> ys(a);
    for (int i = 0; i < b; i++) {
      ys.at(dp[i] - 1) = gh[i];
    }
    if (a == 1)
      t = ys.at(0);
    else if (a == 2)
      t = ys.at(0) * 10 + ys.at(1);
    else if (a == 3)
      t = ys.at(0) * 100 + ys.at(1) * 10 + ys.at(2);
    if (a == 1)
      cout << t;
    else if (a == 2 & t >= 10)
      cout << t;
    else if (a == 3 & t >= 100)
      cout << t;
    else
      cout << -1;
  }
}
