#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m, a, b;
  cin >> n >> m;
  map<int, int> c;
  bool duplicate = 0;
  for (int i = 0; i < (m); i++) {
    cin >> a >> b;
    if (c.count(a) == 1 && c[a] != b)
      duplicate = 1;
    else
      c[a] = b;
  }
  if (duplicate)
    cout << -1 << endl;
  else {
    int ans = -1;
    for (int i = 1; i < (1000); i++) {
      string si = to_string(i);
      bool check = 1;
      for (auto i = c.begin(); i != c.end(); ++i) {
        int key = i->first;
        int value = i->second;
        int ci = si[key - 1] - '0';
        if (ci != value) {
          check = 0;
          break;
        }
      }
      if (check) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
