#include <bits/stdc++.h>
using namespace std;
int keta(int val) {
  long long k = 0;
  while (val > 0) {
    val /= 10;
    k++;
  }
  return k;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (mp.count(s) != 0 and mp[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
    mp[s] = c;
  }
  for (int i = 0; i <= 999; i++) {
    if (keta(i) != n) continue;
    string s = to_string(i);
    bool flag = true;
    for (auto j : mp) {
      if (s[j.first - 1] - '0' != j.second) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
