#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long int inf64 = 1e18 + 5;
map<int, int> mp;
int work(int n) {
  for (int i = 1; i < 1e4 + 5; i++) {
    int x = i;
    vector<int> v;
    while (x) {
      v.push_back(x % 10);
      x /= 10;
    }
    int l = v.size();
    if (l != n) continue;
    reverse(v.begin(), v.end());
    bool poss = true;
    for (auto it : mp) {
      if (it.second != v[it.first - 1]) {
        poss = false;
        break;
      }
    }
    if (poss) return i;
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, i;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (mp[x]) {
      if (mp[x] != y) {
        cout << -1;
        return 0;
      }
    }
    mp[x] = y;
  }
  cout << work(n);
}
