#include <bits/stdc++.h>
using namespace std;
const int INF = 1000100010;
int main() {
  int n, m;
  cin >> n >> m;
  int s[n], c[n];
  set<int> set1, set2, set3;
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1) set1.insert(c[i]);
    if (s[i] == 2) set2.insert(c[i]);
    if (s[i] == 3) set3.insert(c[i]);
  }
  if (set1.size() > 1 || set2.size() > 1 || set3.size() > 1) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 3) {
    if (set1.size() == 0) set1.insert(1);
    if (set2.size() == 0) set2.insert(0);
    if (set3.size() == 0) set3.insert(0);
    if (*set1.begin() == 0) {
      cout << -1 << endl;
      exit(0);
    }
    ans = *set1.begin() * 100 + *set2.begin() * 10 + *set3.begin();
  }
  if (n == 2) {
    if (set1.size() == 0) set1.insert(1);
    if (set2.size() == 0) set2.insert(0);
    if (*set1.begin() == 0) {
      cout << -1 << endl;
      exit(0);
    }
    if (set3.size() > 0) {
      cout << -1 << endl;
      exit(0);
    }
    ans = *set1.begin() * 10 + *set2.begin();
  }
  if (n == 1) {
    if (set1.size() == 0) set1.insert(1);
    if (set2.size() > 0) {
      cout << -1 << endl;
      exit(0);
    }
    if (set3.size() > 0) {
      cout << -1 << endl;
      exit(0);
    }
    ans = *set1.begin();
  }
  cout << ans << endl;
}
