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