#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-7;
const int N = 510;
int vis[4], a[4];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  memset(vis, 0, sizeof(vis));
  memset(a, 0, sizeof(a));
  bool f = true;
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (vis[x] && a[x] != y) {
      f = false;
    } else {
      vis[x] = 1;
      a[x] = y;
    }
  }
  if (f) {
    if (a[1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 1; i <= 3; ++i) {
      cout << a[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
