#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
int a[100];
int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios_base::sync_with_stdio(false);
  memset(a, -1, sizeof a);
  int n, m;
  cin >> n >> m;
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] != c && a[s] != -1) flag = false;
    a[s] = c;
  }
  if (flag && n == 1) {
    if (a[0] == -1) {
      cout << 0;
    } else {
      cout << a[0];
    }
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != -1) break;
    a[i] = 1;
  }
  if (flag && a[0]) {
    for (int i = 0; i < n; i++) {
      cout << (a[i] == -1 ? 0 : a[i]);
    }
  } else {
    cout << -1;
  }
  return 0;
}
