#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  if (n == 1) {
    int ans = 10;
    for (int i = 0; i < (m); i++) {
      if (s[i] > 0) {
        cout << -1 << endl;
        return 0;
      } else {
        if (ans == 10) {
          ans = c[i];
        } else if (ans != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    cout << ans << endl;
    return 0;
  } else if (n == 2) {
    for (int i = 0; i < (m); i++) {
      if (s[i] > 1 || (s[i] == 0 && c[i] == 0)) {
        cout << -1 << endl;
        return 0;
      }
    }
    string ans = "aa";
    for (int i = 0; i < (m); i++) {
      if (ans[s[i]] == 'a') {
        ans[s[i]] = c[i] + '0';
      } else if (ans[s[i]] != c[i] + '0') {
        cout << -1 << endl;
        return 0;
      }
    }
    if (ans[0] == 'a') {
      cout << 1;
    } else {
      cout << ans[0];
    }
    if (ans[1] == 'a') {
      cout << 0;
    } else {
      cout << ans[1];
    }
    cout << endl;
    return 0;
  } else if (n == 3) {
    for (int i = 0; i < (m); i++) {
      if (s[i] > 2 || (s[i] == 0 && c[i] == 0)) {
        cout << -1 << endl;
        return 0;
      }
    }
    string ans = "aaa";
    for (int i = 0; i < (m); i++) {
      if (ans[s[i]] == 'a') {
        ans[s[i]] = c[i] + '0';
      } else if (ans[s[i]] != c[i] + '0') {
        cout << -1 << endl;
        return 0;
      }
    }
    if (ans[0] == 'a') {
      cout << 1;
    } else {
      cout << ans[0];
    }
    if (ans[1] == 'a') {
      cout << 0;
    } else {
      cout << ans[1];
    }
    if (ans[2] == 'a') {
      cout << 0;
    } else {
      cout << ans[2];
    }
    cout << endl;
    return 0;
  }
}
