#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;
int s[10], c[10];
vector<P> a;

int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> N >> M;
  rep(i, M) {
    cin >> s[i] >> c[i];
    a.push_back(P(s[i], c[i]));
  }
  sort(ALL(a));
  int now=0;
  int idx=0;
  int th = 0;
  int ans = 0;
  rep(i, M) {
    if (a[i].first && a[i].second==0) {
      cout << -1 << "\n";
      return 0;
    }
    if (a[i].first!=now) {
      now = a[i].first;
      th = a[i].second;
      ans+=a[i].second*pow(10, N-a[i].first);
      continue;
    }
    if (th!=a[i].second) {
      cout << -1 << "\n";
      return 0;
    }
  }
  
  if (a[0].first!=1) {
    ans+=1*pow(10, N-1);
  }

  cout << ans << "\n";
  return 0;
}#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;
int s[10], c[10];
vector<P> a;

int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> N >> M;
  rep(i, M) {
    cin >> s[i] >> c[i];
    a.push_back(P(s[i], c[i]));
  }
  sort(ALL(a));
  int now=0;
  int idx=0;
  int th = 0;
  int ans = 0;
  rep(i, M) {
    if (a[i].first && a[i].second==0) {
      cout << -1 << "\n";
      return 0;
    }
    if (a[i].first!=now) {
      now = a[i].first;
      th = a[i].second;
      ans+=a[i].second*pow(10, N-a[i].first);
      continue;
    }
    if (th!=a[i].second) {
      cout << -1 << "\n";
      return 0;
    }
  }
  
  if (a[0].first!=1) {
    ans+=1*pow(10, N-1);
  }

  cout << ans << "\n";
  return 0;
}