#include <bits/stdc++.h>
using namespace std;
int sc1() {
  int x;
  scanf("%d", &x);
  return x;
}
long long sc2() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int mod = 1e9 + 7;
const int inf = (int)2e9 + 5;
const long long Inf = (long long)1e18 + 5;
const int N = 5e6 + 5;
inline int add(int a, int b) {
  a += b;
  return a >= mod ? a - mod : a;
}
inline int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + mod : a;
}
inline int mul(int a, int b) { return (long long)a * b % mod; }
int solve() {
  int n = sc1();
  int m = sc1();
  std::vector<int> v[4];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  std::vector<int> ans;
  for (int i = 1; i <= n; i++) {
    set<int> st;
    for (int j = 0; j < v[i].size(); j++) {
      st.insert(v[i][j]);
    }
    if (st.size() > 1) {
      cout << -1 << endl;
      return 0;
    }
    if (st.size() == 0) {
      if (i == 1)
        ans.push_back(1);
      else
        ans.push_back(0);
    }
    if (st.size() == 1) {
      if (i == 1) {
        if (v[i][0] == 0) {
          cout << -1 << endl;
          return 0;
        } else
          ans.push_back(v[i][0]);
      } else {
        ans.push_back(v[i][0]);
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
int main() {
  int test = 1, tc = 0;
  while (test--) {
    solve();
  }
  return 0;
}
