#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, M = 4;
int n, m;
int num[M];
int get(int t) {
  if (!t) return 1;
  int cnt = 0;
  while (t) {
    t /= 10;
    cnt++;
  }
  return cnt;
}
bool check(int t) {
  vector<int> a;
  while (t) {
    a.push_back(t % 10);
    t /= 10;
  }
  reverse(a.begin(), a.end());
  for (int i = 0; i < a.size(); i++)
    if (a[i] != num[i + 1]) return false;
  return true;
}
int main() {
  cin >> n >> m;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (num[s] && num[s] != c) {
      puts("-1");
      return 0;
    } else
      num[s] = c;
  }
  for (int i = 0; i < N; i++)
    if (get(i) == n && check(i)) {
      cout << i << endl;
      return 0;
    }
  puts("-1");
  return 0;
}
