#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int a[4];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= 3; i++) a[i] = -1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1 && y == 0) {
      cout << -1;
      return;
    }
    if (a[x] == -1)
      a[x] = y;
    else if (a[x] != y) {
      cout << -1;
      return;
    }
  }
  for (int i = 1; i <= 3; i++) {
    if (a[i] == -1)
      cout << (i == 1 ? 1 : 0);
    else
      cout << a[i];
  }
}
int main() {
  ios::sync_with_stdio(false);
  int q = 1;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}
