#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[3] = {-1, -1, -1}, ans;
  cin >> n >> m;
  bool f = 0;
  for (int(i) = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (n == 1) {
      if (a[2] == -1)
        ans = c;
      else if (a[2] != c)
        f = 1;
    } else if (n == 2) {
      if (s == 1) {
        if (!c)
          f = 1;
        else if (a[1] == -1)
          a[1] = c;
        else if (a[1] != c)
          f = 1;
      } else if (s == 2) {
        if (a[2] == -1)
          a[2] = c;
        else if (a[2] != c)
          f = 1;
      }
    } else if (n == 3) {
      if (s == 1) {
        if (!c)
          f = 1;
        else if (a[0] == -1)
          a[0] = c;
        else if (a[0] != c)
          f = 1;
      } else if (s == 2) {
        if (a[1] == -1)
          a[1] = c;
        else if (a[1] != c)
          f = 1;
      } else if (s == 3) {
        if (a[2] == -1)
          a[2] = c;
        else if (a[2] != c)
          f = 1;
      }
    }
    if (f) break;
  }
  for (int(i) = 0; i < (3); i++)
    if (a[i] == -1) a[i] = 0;
  if (n == 1)
    ans = a[2];
  else if (n == 2) {
    ans = a[1] * 10 + a[2];
    if (ans < 10) ans += 10;
  } else if (n == 3) {
    ans = a[0] * 100 + a[1] * 10 + a[2];
    if (ans < 100) ans += 100;
  }
  cout << (f ? -1 : ans);
}
