#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[6] = {0, 1, 0, -1, 1, -1};
const int vy[6] = {1, 0, -1, 0, 1, 1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, int> memo;
  vector<int> s(4, -1);
  string ans = "";
  for (ll i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    if (s[x] == -1) {
      s[x] = y;
    } else if (s[x] == y) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i <= 3; ++i) {
    if (s[i] == 0 && ans == "") {
      cout << -1 << endl;
      return 0;
    }
    if (s[i] != -1) {
      ans += to_string(s[i]);
    } else if (ans != "") {
      ans += to_string(0);
    }
  }
  cout << ans << endl;
  cout << endl;
  return 0;
}
