#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e5 + 5;
long long num[12];
long long q[12][2];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    num[i] = -1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> q[i][0] >> q[i][1];
    num[q[i][0]] = q[i][1];
  }
  bool can = true;
  for (int i = 1; i <= m; i++) {
    if (num[q[i][0]] != q[i][1]) can = false;
  }
  if (num[1] == -1) can = false;
  for (int i = 1; i <= n; i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (num[i] == 0) cnt++;
  }
  if (cnt == n) can = false;
  if (!can) {
    cout << -1 << endl;
    return;
  }
  for (int i = 1; i <= n; i++) {
    cout << num[i];
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
