#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  int s, c, ans = 1;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    s--;
    if (a[s] == -1 || a[s] == c)
      a[s] = c;
    else
      ans = -1;
  }
  if (ans == -1 || (n > 1 && a[0] == 0))
    cout << -1;
  else
    for (int i = 0; i < n; ++i) {
      if (a[i] == -1) {
        if (i == 0 && m > 0)
          cout << 1;
        else
          cout << 0;
      } else
        cout << a[i];
    }
}
