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