#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x, y;
} s[55];
bool cmp(node a, node b) {
  long long d1 = a.x * a.x + a.y * a.y;
  long long d2 = b.x * b.x + b.y * b.y;
  return d1 < d2;
}
int main() {
  int n, m;
  cin >> n >> m;
  int a[5];
  memset(a, -1, sizeof(a));
  int flag = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x] == -1) {
      a[x] = y;
    } else if (a[x] == y)
      continue;
    else
      flag = 0;
  }
  if (flag == 0)
    cout << "-1";
  else {
    if (n == 1) cout << a[1];
    if (n == 2) {
      if (a[1] == -1 || a[1] == 0)
        cout << "-1";
      else {
        if (a[2] == -1) a[2] = 0;
        cout << a[1] << a[2];
      }
    }
    if (n == 3) {
      if (a[1] == -1 || a[1] == 0)
        cout << -1;
      else {
        if (a[2] == -1) a[2] = 0;
        if (a[3] == -1) a[3] = 0;
        cout << a[1] << a[2] << a[3];
      }
    }
  }
  cout << endl;
  return 0;
}
