#include <bits/stdc++.h>
using namespace std;
const int N = 4;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  map<int, int> mp;
  bool q = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (mp[x]) {
      if (mp[x] != y) q = 1;
    } else {
      mp[x] = y;
    }
  }
  if (q) {
    cout << -1;
    return 0;
  }
  string ans = "";
  for (int i = 1; i <= n; i++) {
    if (mp[i]) {
      ans += char(mp[i] + '0');
      continue;
    }
    ans += '0';
    mp[i] = 0;
  }
  if (ans[0] == '0' && n != 1) {
    cout << -1;
    return 0;
  }
  for (auto x : mp) {
    cout << x.second;
  }
}
