#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const long long limit = 2e9;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1, 1, 2, 2, 1, -1, -2, -2};
const int ky[] = {2, 2, 1, -1, -2, -2, -1, 1};
struct dsu {
  int parent[N];
  int cont;
  void make_set(int n) {
    for (int i = 1; i <= n; i++) parent[i] = i;
    cont = n;
  }
  int find_set(int v) {
    if (v == parent[v]) return v;
    return find_set(parent[v]);
  }
  void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
      parent[b] = a;
      cont--;
    }
  }
};
int v[4];
int main() {
  memset(v, 0, sizeof(v));
  int n, m;
  cin >> n >> m;
  int second, c;
  for (int i = 1; i <= m; i++) {
    cin >> second >> c;
    if (v[second] == 0)
      v[second] = c;
    else if (v[second] != c) {
      cout << -1;
      return 0;
    }
  }
  if (v[n] == 0)
    cout << -1;
  else {
    for (int i = 1; i <= n; i++) cout << v[i];
  }
  return 0;
}
