#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, mm;
  cin >> n >> mm;
  map<int, int> m;
  vector<pair<int, int> > v(n);
  for (int i = 0; i < mm; i++) {
    cin >> v[i].first >> v[i].second;
    if (m[v[i].first] && m[v[i].first] != v[i].second) {
      cout << -1;
      return 0;
    }
    m[v[i].first] = v[i].second;
  }
  bool ok = 0;
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      ok = 1;
      string s = to_string(i);
      for (int j = 1; j <= s.length(); j++) {
        if (s[j - 1] != m[j] + '0') {
          ok = 0;
          break;
        }
      }
      if (ok) {
        cout << i;
        return 0;
      }
    }
  }
  if (m[1] == 0) {
    cout << -1;
    return 0;
  }
  if (n == 2) {
    for (int i = 10; i < 100; i++) {
      ok = 1;
      string s = to_string(i);
      for (int j = 1; j <= s.length(); j++) {
        if (s[j - 1] != '0' + m[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        cout << i;
        return 0;
      }
    }
  }
  if (n == 3) {
    for (int i = 100; i < 1000; i++) {
      ok = 1;
      string s = to_string(i);
      for (int j = 1; j <= s.length(); j++) {
        if (m[j])
          if (s[j - 1] != '0' + m[j]) {
            ok = 0;
            break;
          }
      }
      if (ok) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
}
