#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int ans[1223];
int vis[1223];
int q[123][2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  bool imp = false;
  for (int i = 0; i < m; i++) {
    cin >> q[i][0] >> q[i][1];
  }
  for (int i = 1; i < 10000; i++) {
    vector<int> v;
    int x = i;
    while (x) {
      v.push_back(x % 10);
      x /= 10;
    }
    reverse(v.begin(), v.end());
    if (v.size() != n) continue;
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      if (v[q[j][0] - 1] == q[j][1]) cnt++;
    }
    if (cnt == m) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
