#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[5];
bool ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  memset(a, -1, sizeof(a));
  for (int i = 0; i < m; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    if (a[t1] == -1) {
      a[t1] = t2;
    } else if (a[t1] != t2)
      ans = 1;
    if (ans) break;
  }
  if (a[1] == 0 && n > 1) ans = 1;
  if (ans) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 2; i <= n; i++)
    if (a[i] == -1) a[i] = 0;
  for (int i = 1; i <= n; i++) cout << a[i];
  cout << endl;
}
